Hello,
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:
timeline.setSelectedLayers(0);
if( timeline.getLayerProperty("name") != "ACTIONS" ){
timeline.addNewLayer('ACTIONS');
timeline.setSelectedLayers(0);
}
var trgt = timeline.layers[0].frames[0];
trgt.actionScript = "";
trgt.actionScript +='\n // ADD as3 Code line by line';
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.setSelectedLayers(0);
$timeline.addNewLayer('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
if(test)
{
trace('It worked!');
}
]]></xml>
Re: the formatting, you just need to paste the code to and from notepad first, so the rich formatting is removed :)
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!
http://www.xjsfl.com/support/api/text/template