Here's the scenario:
We have a creative team that operates in Flash CS5.5 and produces SWF assets which have both graphics elements and actionscript code in them, and an engineering team which authors .as files and builds "code SWFs". The code SWF files must load or embed the creative assets and interact with the code therein for our apps to function.
For iOS mobile development, there is another consideration - it is not possible to load runtime code in an AIR app packages for iOS because of Apple TOS (see related question). Hence, it is not possible to use a Loader to load SWFs in an iOS environment and retain their code.
Embedding a SWF into an ActionScript file the standard way results in a Loader that loads the embedded SWF directly as bytes. This results in access to the top-level, main timeline as follows:
[Embed(source="embed_test.swf")]
private var no_aot_support:Class;
public function main():void
{
var no_ios:* = new no_aot_support();
addChild(no_ios);
no_ios.addEventListener(Event.COMPLETE, function():void {
var timeline:MovieClip = no_ios.getChildAt(0).getChildAt(0);
trace(timeline.foo); // foo variable exists, output is 'blah'
});
}
However, this embedding mechanism doesn't work on iOS devices because runtime-code is not allowed per Apple's TOS - all code must be passed through the ahead-of-time compiler (AOTCompiler) at compile-time, and the SWF embedded in this way does not meet this criteria.
Asking around, I found that one can use a class-level embed to get around this, as a class-level embed does go through the compiler and will result in working code under iOS:
package
{
import flash.display.MovieClip;
[Embed(source="embed_test.swf", symbol="Symbol1")]
public final dynamic class anim extends MovieClip { };
}
This works fine, but I don't want to reference a symbol in the SWF, I want the whole swf (aka reference the main timeline), but the following results in a compiler error:
package
{
import flash.display.MovieClip;
[Embed(source="embed_test.swf")]
public final dynamic class anim extends MovieClip { };
}
I've also decompiled the SWF, found the main timeline symbol, and tried this:
package
{
import flash.display.MovieClip;
[Embed(source="embed_test.swf", symbol="embed_test_fla.MainTimeline")]
public final dynamic class anim extends MovieClip { };
}
But the compiler insists this symbol doesn't exist.
Since I have many, many SWF assets, I need a solution that doesn't involve changing my whole workflow (i.e. going into each FLA and making changes). This should be possible, and if not, this is a workflow problem Adobe should address.
So here I am stuck - regular embeds get the MainTimeline but don't work in iOS, class-level embeds work in iOS and can't access the MainTimeline.
Feel free to download my expample project and play with this.
root
andstage
properties should be enough to access the main timeline. No need to use a loader, neither in an iOS project, nor in any other project. greenethumb.com/article/23/… – weltraumpirat