A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: Need to convert a file from AS2 to AS3

  1. #1
    Member
    Join Date
    Aug 2000
    Location
    Cornwall, UK
    Posts
    44

    Need to convert a file from AS2 to AS3

    I've just discovered that a very simple animation I've created can't be uploaded to its destination webspace because it's AS2 and the webspace says it needs to be AS3.

    As I always deal with really uncomplicated animations I've never mastered AS3 and am now completely at a loss as to how to proceed.

    The compiler error window tells me that the following code isn't supported in AS3

    Code:
    //Movieclip GotoAndPlay Behavior
    	_root.board.gotoAndPlay("break");
    //End Behavior
    I have no idea how to fix this. I've been researching and reading and going 'round in circles for more than three hours, now, on a job that only took 30 minutes to originate. I'm at my wits' end

    Can anyone help? Please.

    Frannie x

  2. #2
    Member
    Join Date
    Aug 2000
    Location
    Cornwall, UK
    Posts
    44
    Apologies, I should have indicated that the above code resides in a frame.

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Seriously? What did you find in those 3 hours? Did you find http://www.adobe.com/devnet/flash/ar...plication.html
    or http://actionscriptcheatsheet.com/bl...free-download/ or
    http://www.adobe.com/content/dotcom/.../learning.html or
    http://www.adobe.com/devnet/actionsc...quick_ref.html ?

    That was about 2 minutes of googling for "adobe as2 as3 migration"

    To answer your specific question, _root has been replaced by root (no _). In fact, all the _somethings have been replaced by no underscore somethings.
    The root property is typed as DisplayObject, which does not have a "board" property and is not dynamic, so you'll need to cast it to MovieClip, which is dynamic.

    Code:
    MovieClip(root).board.gotoAndPlay("break");
    Of course, if that code was in your main timeline and not some other movieclip, then you don't need the root part at all because the main timeline is the root.
    Code:
    board.gotoAndPlay("break");

  4. #4
    Member
    Join Date
    Aug 2000
    Location
    Cornwall, UK
    Posts
    44
    Many thanks... I did, indeed find not just one but all of the links you've kindly mentioned (hence me indicating that that I'd been reading).

    Sadly I just wasn't able to make head nor tail of any of it. As said... I've been chugging along happily for years making simple animations and using nothing more complex than the preset 'behaviors' and have now, suddenly been faced with learning, from ground zero and on a deadline, the seemingly incomprehensible AS3.

    Thank you for the breakdown... I'll study it and try my best to understand it all :-)

  5. #5
    Member
    Join Date
    Aug 2000
    Location
    Cornwall, UK
    Posts
    44
    Oh dear... I carefully placed the following:

    Actionscript Code:
    MovieClip(root).board.gotoAndPlay("break");

    in the same frame that had contained the original code and the 'Output' window immediately leapt up with:

    WARNING: Actions on button or MovieClip instances are not supported in ActionScript 3.0. All scripts on object instances will be ignored.
    Sadly, I'll now have to concede defeat and call time on this one as it's taken many, many more hours than had been accounted for and is still not working.

    Huge thanks for the proffered help, though. It was much appreciated x

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You can place code in MovieClips' timelines (frames), but not on the clips themselves. If you want to associate code with the instance itself, you should create a class which has your code and associate your library symbols with that class.

  7. #7
    Junior Member
    Join Date
    Jan 2015
    Posts
    2
    can you help me to conver this AS3 in AS2 please??!!!

    package {
    import flash.display.*;
    import flash.events.*;
    import flash.ui.*;

    public class Memory extends MovieClip
    {
    private var score, life:Number;
    private var doLoseLife, gotoWin, gotoLose:Boolean;
    private var firstCard, secondCard:Card;
    private var cardValues, cards:Array;

    public function Memory()
    {

    }

    //All Start Functions
    public function startMenu()
    {
    stop();
    btnStartGame.addEventListener(MouseEvent.CLICK, gotoStartGame);
    btnHowToPlay.addEventListener(MouseEvent.CLICK, gotoHowToPlay);
    }

    public function startHowToPlay()
    {
    btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
    }

    public function startWin()
    {
    btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
    }

    public function startLose()
    {
    btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
    }

    public function startGame()
    {
    score = 0;
    life = 10;
    doLoseLife = false;
    gotoWin = false;
    gotoLose = false;
    firstCard = null;
    secondCard = null;
    cards = new Array();

    setupGame();

    //Shuffle
    cardValues = new Array(“card1″,”card1″,”card2″,”card2″,”c ard3″,”card3″,”card4″,”card4″,
    “card5″,”card5″,”card6″,”card6″,”card7″, ”card7″);
    for (var i=0; i<100; i++)
    {
    var swap1 = Math.floor(Math.random()*14);
    var swap2 = Math.floor(Math.random()*14);

    var tempValue = cardValues[swap1];
    cardValues[swap1] = cardValues[swap2];
    cardValues[swap2] = tempValue;
    }

    //Deal
    for (var i=0; i<14; i++)
    {
    cards[i].hiddenValue = cardValues[i];
    cards[i].addEventListener(MouseEvent.CLICK, flipCard);
    }

    addEventListener(Event.ENTER_FRAME,update);

    stage.focus = this;
    }

    public function startLevel2()
    {
    life = 10;
    doLoseLife = false;
    gotoWin = false;
    gotoLose = false;
    firstCard = null;
    secondCard = null;
    cards = new Array();

    setupGame();

    //Shuffle
    cardValues = new Array("card1","card1","card2","card2","card3","car d3","card4","card4",
    "card5","card5","card6","card6","card7","card7","c ard8","card8");
    for (var i=0; i<100; i++)
    {
    var swap1 = Math.floor(Math.random()*14);
    var swap2 = Math.floor(Math.random()*14);

    var tempValue = cardValues[swap1];
    cardValues[swap1] = cardValues[swap2];
    cardValues[swap2] = tempValue;
    }

    //Deal
    for (var i=0; i<16; i++)
    {
    cards[i].hiddenValue = cardValues[i];
    cards[i].addEventListener(MouseEvent.CLICK, flipCard);
    }

    addEventListener(Event.ENTER_FRAME,update);

    stage.focus = this;
    }

    private function setupGame()
    {
    //Check the classes of the movieclips and push them into the
    //appropriate arrays
    for (var i=0; i= 70)
    {
    gotoAndStop(“level2″)
    }
    }
    else if (currentLabel == “level2″)
    {
    if (score >= 150)
    {
    gotoWin = true;
    }
    }

    if (life <= 0)
    {
    gotoLose = true;
    }
    }

    private function handleDraw()
    {
    //Handle display
    txtScoreP1.text = String(score);
    txtLife.text = String(life);
    }

    private function triggerGoToWin()
    {
    removeEventListener(Event.ENTER_FRAME, update);
    gotoAndStop("win");
    }

    private function triggerGoToLose()
    {
    removeEventListener(Event.ENTER_FRAME, update);
    gotoAndStop("lose");
    }

    //Misc Functions
    private function resetGame()
    {
    for (var i in cards)
    cards[i].gotoAndStop("back");
    }

    }//end class
    }//end package

  8. #8
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,#

    Thas a bit of request with so little info from yourself.

    So here is the same code with a few (nearly all ) things converted and the as3 stuff commented out, you should be able to do it from there yourself, it does have errors though.
    PHP Code:
    //package {
    //import flash.display.*;
    //import flash.events.*;
    //import flash.ui.*;

    //public class Memory extends MovieClip
    //{
    /*private*/ 
    var scorelife:Number;
    /*rivate*/ var doLoseLifegotoWingotoLose:Boolean;
    /*private*/ var firstCardsecondCard:Card;
    /*private*/ var cardValuescards:Array;

    /*public function Memory()
    {

    }*/

    //All Start Functions
    /*public*/ 
    function startMenu()
    {
        
    stop();
        
    //btnStartGame.addEventListener(MouseEvent.CLICK, gotoStartGame);
        //btnHowToPlay.addEventListener(MouseEvent.CLICK, gotoHowToPlay);
        
    btnStartGame.onPress gotoStartGame;
        
    btnHowToPlay.onPress gotoHowToPlay;
    }

    /*public*/ function startHowToPlay()
    {
        
    //btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
        
    btnBack.onPress gotoMenu;
    }

    /*public*/ function startWin()
    {
        
    //btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
        
    btnBack.onPress gotoMenu;
    }

    /*public*/ function startLose()
    {
        
    //btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
        
    btnBack.onPress gotoMenu;
    }

    /*public*/ function startGame()
    {
        
    score 0;
        
    life 10;
        
    doLoseLife false;
        
    gotoWin false;
        
    gotoLose false;
        
    firstCard null;
        
    secondCard null;
        
    cards = new Array();

        
    setupGame();
        
        
    //Shuffle
        
    cardValues = new Array("card1","card1","card2","card2","card3","car d3","card4","card4",
        
    "card5","card5","card6","card6","card7","card7");
        
        for (var 
    i=0i<100i++)
        {
            var 
    swap1 Math.floor(Math.random()*14);
            var 
    swap2 Math.floor(Math.random()*14);

            var 
    tempValue cardValues[swap1];
            
    cardValues[swap1] = cardValues[swap2];
            
    cardValues[swap2] = tempValue;
        }

        
    //Deal
        
    for (var i=0i<14i++)
        {
            
    cards[i].hiddenValue cardValues[i];
            
    //cards[i].addEventListener(MouseEvent.CLICK, flipCard);
            
    cards[i].onPress flipCard;
        }
        
    //addEventListener(Event.ENTER_FRAME,update);
        
    this.onEnterFrame update;
        
        
    Stage.focus this;
    }

    /*public*/ function startLevel2()
    {
        
    life 10;
        
    doLoseLife false;
        
    gotoWin false;
        
    gotoLose false;
        
    firstCard null;
        
    secondCard null;
        
    cards = new Array();

        
    setupGame();

        
    //Shuffle
        
    cardValues = new Array("card1","card1","card2","card2","card3","car d3","card4","card4",
        
    "card5","card5","card6","card6","card7","card7","c ard8","card8");
        for (var 
    i=0i<100i++)
        {
            var 
    swap1 Math.floor(Math.random()*14);
            var 
    swap2 Math.floor(Math.random()*14);

            var 
    tempValue cardValues[swap1];
            
    cardValues[swap1] = cardValues[swap2];
            
    cardValues[swap2] = tempValue;
        }

        
    //Deal
        
    for (var i=0i<16i++)
        {
            
    cards[i].hiddenValue cardValues[i];
            
    //cards[i].addEventListener(MouseEvent.CLICK, flipCard);
            
    cards[i].onPress flipCard;
        }

        
    //addEventListener(Event.ENTER_FRAME,update);
        
    this.onEnterFrame update;

        
    Stage.focus this;
    }

    /*private*/ function setupGame()
    {
        
    //Check the classes of the movieclips and push them into the
        //appropriate arrays
        
    for (var i=0i70)
        {
            
    gotoAndStop("level2")
        }
    }
    else if (
    currentLabel == "level2")
    {
        if (
    score >= 150)
        {
            
    gotoWin true;
        }
    }

    if (
    life <= 0)
    {
        
    gotoLose true;
    }
    }

    /*private*/ function handleDraw()
    {
        
    //Handle display
        
    txtScoreP1.text String(score);
        
    txtLife.text String(life);
    }

    /*private*/ function triggerGoToWin()
    {
        
    //removeEventListener(Event.ENTER_FRAME, update);
        
    delete this.onEnterFrame;
        
    gotoAndStop("win");
    }

    /*private*/ function triggerGoToLose()
    {
        
    //removeEventListener(Event.ENTER_FRAME, update);
        
    delete this.onEnterFrame;
        
    gotoAndStop("lose");
    }

    //Misc Functions
    /*private*/ 
    function resetGame()
    {
        for (var 
    i in cards)
        
    cards[i].gotoAndStop("back");
    }

    //}//end class
    //}//end package 

  9. #9
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    "incomprehensible AS3" lol
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  10. #10
    Senior Member
    Join Date
    Aug 2012
    Posts
    115
    imcomprihensi for you you mean, you can do it.

    look at list of code you do in signeturre, must be goode

  11. #11
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Well they never did get back to find out if they could finish it??

  12. #12
    Registered User
    Join Date
    Apr 2015
    Posts
    1
    can you help me to conver this AS2 in AS3 please??!!!

    // Initialize variables.
    maxLines = 25; // Maximum number of lines at once.
    minScale = 10; // Minimum scale of a line.
    maxScale = 100; // Maximum scale of a line.
    // Create an empty Movieclip to hold the Matrix.
    theMatrix = createEmptyMovieClip('MatrixCode',1);
    curLines = 0; // Keeps track of the current number of lines.
    // ----------------------
    // Generating the Matrix.
    // ----------------------
    theMatrix.onEnterFrame = function(){
    // Check that the current number of lines is less than the maximum allowed.
    if(curLines <= maxLines){
    curLines++; // Increment the number of lines.
    // Create a new line.
    codeLine = this.createEmptyMovieClip('codeLine',curLines);
    // Generate a random scale for the line.
    // This simulates lines at different distances.
    var ranScale = Math.round(Math.random() * (maxScale-minScale)) + minScale;
    codeLine._xscale = codeLine._yscale = ranScale;
    // Position the line at a random X location.
    codeLine._x = Math.random() * Stage.width;
    // Determine line speed based on the distance.
    codeLine.speed = (codeLine._xscale)/10;
    // ---------------------------------------------
    // Creating a line of multiple pods (characters)
    // ---------------------------------------------
    codeLine.myCodes = []; // Array to store individual pods.
    numPods = 0; // Number of pods.
    while(codeLine._height < Stage.height){
    numPods++; // Increment the number of pods.
    // Attach a single pod to the line of code.
    pod = codeLine.attachMovie('one_pod','pod'+numPods,numPo ds);
    codeLine.myCodes.push(pod); // store pod.
    // Position pod above the last one (vertical lines)
    pod._y -= (pod._height+2) * numPods;
    // Choose a random Matrix character.
    // Character Codes for lower case letters are between 96 & 123
    pod.the_one.Neo.text = chr(Math.round(Math.random() * 27) + 96);
    }
    // ----------------------------
    // Initialize the white pulse.
    // ----------------------------
    // Store pod position to start at.
    codeLine.ind = 0;
    // Store delay between pulses.
    codeLine.delay = codeLines.myCodes.length;
    // ------------------------------------
    // Animating each line of code.
    // ------------------------------------
    codeLine.onEnterFrame = function(){
    // -------------------------------
    // Vertical animation of the line.
    // -------------------------------
    // Every frame make the line move down by it's speed.
    this._y += this.speed;
    // Check if the line of code has animated off the Stage
    if(this._y - this._height >= Stage.height) {
    // Yes, so allow an additional line to be generated.
    maxLines++;
    // Remove this line and free memory.
    this.removeMovieClip();
    }
    // ----------------------------
    // Animating the white pulse.
    // ----------------------------
    // Get next pod to affect.
    this.curCode = this.myCodes[this.ind];
    // If the pod is not currently animating, start its animation.
    if(this.curCode._currentframe == 1) this.curCode.play();
    // Check if we have reached the end of the line.
    if(this.ind < this.myCodes.length and this.delay != 0){
    // No, then move on to next character.
    this.ind++;
    // Decrease the delay before next pulse.
    this.delay--;
    } else {
    // Yes, then reset the character position.
    this.ind = 0;
    // Reset the delay before next pulse.
    this.delay = this.myCodes.length;
    }
    }
    }
    }

  13. #13
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    looks like you are trying to do The Matrix numbers things.
    Attach the AS2 file and we can try to convert it for you.

  14. #14
    Registered User
    Join Date
    Mar 2017
    Posts
    1
    Hey guy,

    please help me out converting the code below into as3. I have no ideea what is "SHEMA" , "BASE", "GLANCE" etc for AS3. THanks a lot.

    function CopyFromShema(sframe)
    {
    SHEMA.gotoAndStop(sframe);
    GLANCE.filters = SHEMA.GLANCE.filters;
    BASE.filters = SHEMA.BASE.filters;
    CAPTION.filters = SHEMA.CAPTION.filters;
    }
    SHEMA._visible = false;
    SHEMA.gotoAndStop(1);
    BASE.scale9Grid = new flash.geom.Rectangle(10, 10, 100, 5);
    GLANCE.scale9Grid = new flash.geom.Rectangle(10, 6, 100, 2);
    onRollOver = function ()
    {
    CopyFromShema(3);
    }
    ;
    onRollOut = function ()
    {
    CopyFromShema(2);
    }
    ;
    onPress = function ()
    {
    CopyFromShema(4);
    }
    ;
    onRelease = function ()
    {
    CopyFromShema(3);
    }
    ;
    onDragOver = function ()
    {
    onPress();
    }
    ;
    onDragOut = function ()
    {
    onRollOut();
    }
    ;

  15. #15
    Member
    Join Date
    Oct 2016
    Posts
    54
    Code is AS2 and they are moviclip names

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center