Mat
Mat

Reputation: 11

Help needed with Flash AS2 to AS3 conversion, having major problems

I have a project i need to update form AS2 to AS3 as i need some of the new functions available for vertical centering of text.

My current AS2 code on the time line is as follows.

var dataField =  _root.dataField;
var dataType =  _root.dataType;
var dataPage =  _root.dataPage;
var dataVar =  _root.dataVar;
_root.mc.onRelease = function() {
    getURL("index.php?page="+dataPage+"&num="+dataNum+"&"+dataType+"="+dataVar, "_self");
};

And my external AS file is as follows.

import mx.transitions.Tween;

/**
 *
 *  StandardKey is attached to a movieclip in the library.
 *  It handles the basic button behavior of the keyboard keys.
 *  When each button is placed on the stage, it's instance name
 *  will be the unique ID of the key.
 *
 */
class StandardKey extends MovieClip {


    ///////////////////////////////////////

    //Stage Elements    
    var highlight:MovieClip;
    //End Stage Elements
    var highlightTween:Tween;

    function StandardKey(Void) {
                //Repaint the key with 0 alpha
        highlight._alpha = 0;
    }


    function onPress(Void):Void {

        //Do the highlight animation
        highlightTween.stop();
        highlightTween = new Tween(highlight, "_alpha", mx.transitions.easing.Regular.easeInOut, 100, 0, 10, false);
    }

}

Here is my attempt at moving timeline and external AS2 to AS3

Timeline i now have :

var dataField =  this.dataField;
var dataType =  this.dataType;
var dataPage =  this.dataPage;
var dataVar =  this.dataVar;
var dataNum =  this.dataNum;
_root.mc.onRelease = function() {
navigateToURL(new URLRequest("index.php?page="+dataPage+"&num="+dataNum+"&"+dataType+"="+dataVar, "_self"));
};

External AS3 i have

package {
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.display.MovieClip;

/**
 *
 *  StandardKey is attached to a movieclip in the library.
 *  It handles the basic button behavior of the keyboard keys.
 *  When each button is placed on the stage, it's instance name
 *  will be the unique ID of the key.
 *
 */
public class StandardKey extends MovieClip {


    ///////////////////////////////////////

    //Stage Elements    
    var highlight:MovieClip;
    //End Stage Elements
    var highlightTween:Tween;

    public function StandardKey(Void) {
                //Repaint the key with 0 alpha
        highlight._alpha = 0;
    }


    public function onPress(Void):void {

        //Do the highlight animation
        highlightTween.stop();
        highlightTween = new Tween(highlight, "_alpha", fl.transitions.easing.Regular.easeInOut, 100, 0, 10, false);
    }

}
}

The errors i am currently getting are :

Scene 1, Layer 'Label', Frame 1, Line 6 1120: Access of undefined property _root. Scene 1, Layer 'Label', Frame 1, Line 7 1137: Incorrect number of arguments. Expected no more than 1.

If any one could help me work this out i would appreciate it very much.

Kind regards Mat.

Upvotes: 1

Views: 832

Answers (2)

wuiyang
wuiyang

Reputation: 429

change

_root.mc.onRelease = function() {
navigateToURL(new URLRequest("index.php?page="+dataPage+"&num="+dataNum+"&"+dataType+"="+dataVar, "_self"));
}

to

mc.addEventListener(MouseEvent.CLICK, mcClicked)
function mcClicked(e:Event) {
    navigateToURL(new URLRequest("index.php?page="+dataPage+"&num="+dataNum+"&"+dataType+"="+dataVar, "_self"));
}

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/MouseEvent.html#MouseEvent%28%29

highlight._alpha = 0; to highlight.alpha = 0;

highlightTween = new Tween(highlight, "_alpha", fl.transitions.easing.Regular.easeInOut, 100, 0, 10, false);

to

highlightTween = new Tween(highlight, "alpha", Regular.easeInOut, 100, 0, 10, false);

http://www.republicofcode.com/tutorials/flash/as3tweenclass/

Upvotes: 0

grapefrukt
grapefrukt

Reputation: 27045

Don't use _root, if you absolutely need to reference upwards, the closest AS3 equivalent is stage.

DisplayObject properties no longer start with an underscore (_alpha vs. alpha in your case).

You can't use onRelease, you need to use addEventListener()

Your timeline code makes little, sense, why are you making local vars?

All in all, I'd recommend you reading up on Adobe's migration guide.

Upvotes: 1

Related Questions