appending as3
  • sstarksstark September 2012


    I am looking for a user-friendly way to append as3 code into a timeline. I have it working ( see below ), but it's not elegant.

    In english:

    • select first layer on stage root timeline.
    • test if the name is "ACTIONS", if not make it.
    • clear all as code in the clip
    • write new code into the clip
    if( timeline.getLayerProperty("name") != "ACTIONS" ){
    var trgt = timeline.layers[0].frames[0];
    trgt.actionScript = "";
    trgt.actionScript +='\n // ADD as3 Code line by line';



  • DaveDave September 2012

    Well, it's JSFl. Sometimes it needs to be written longhand!

    My plan was to create Selectors for timelines and frames as well, and I may do that at some point, but elements and items were the most important.

    In the interim, this is probably simpler:

    if($timeline.layers[0].name !== 'ACTIONS')
    $timeline.layers[0].frames[0].actionScript = '//some\n//actionscript\n//ok?';

    You could also load a script from a folder if you want to make the multiline thing easier:

    $timeline.layers[0].frames[0].actionScript = new File('test.jsfl').contents;

    Or, you could embed your script as inline XML:

    $timeline.layers[0].frames[0].actionScript = <xml><![CDATA[// variables
    var test:Boolean = true;

    // test code
    trace('It worked!');

    Re: the formatting, you just need to paste the code to and from notepad first, so the rich formatting is removed :)

  • sstarksstark September 2012

    that's a good idea about bringing in an external file. Will do that. cheers.

  • DaveDave September 2012

    If you want full control over the inserted text, check out the Template class. It makes it super-easy to combine text and values without the usual clumsy string concatenation!


Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with OpenID Sign In with Google Sign In with Twitter

Sign In Apply for Membership