Search code examples
actionscript-3instancemovieclipstage

Recreating stage layout in as3


I have 27 MovieClips in my Library which are all images. At the moment they are positioned on the stage as instances of their parent and then made to function in the first frame of my actions layer. I want to recreate this layout solely in code so there is nothing on the stage. How do I do this?

Thanks in advance. Sam


Solution

  • Right click on a movieclip in the library, then go to Properties. Tick "Export for ActionScript", then check the name where it says "Class". Hit OK. Let's say this name was "Symbol1".

    Then type this script:

    var symbol1:MovieClip = new Symbol1();
    addChild(symbol1);
    

    var symbol1 means you created a variable, MovieClip is the type. This MovieClip variable is a "new " Symbol1 (this was the name in the library, Properties, Class.

    Then add this to the stage:

    addChild(symbol1)
    

    If you want to position it on the stage, set the coordinates of the variable:

    symbol1.x = 10;
    symbol1.y = 10;
    

    puts it to (10, 10).

    Depending on how many objects you have you can type this code for each one of them (don't forget to Export them for actionscript in Library->Properties).

    If you have tons of movieclips and you don't want to type evertyhing, but would rather write some dynamic code, give us a hint on your library structure and how you named your objects.

    Hope this helps.