0
votes

Is it possible to load on frame 2 a swf embed in another swf?

I need to produce a single, main swf that contains a sound swf. The sound swf contains exported sound files for instantiation in code. The sound swfs vary based on the version of the main swf hence the desire to embed at compile time. I currently embed the sound swf in the main swf code using an [Embed] metadata tag which all works. However, this seems to load the swfs on frame 1 and I'd rather it load on frame 2 after my preloader runs.

I've checked around the web and this question seems to get asked but never really answered.

To clarify, I am embedding a swf and its symbols in a main class with code like this:

[Embed(source = 'sound.swf', symbol = 'music')] public var music:Class;

The embed swf and symbols load on the initial main swf load. If I set the sound swf to export on frame 2, it does not compile. Library contents in the main swf load on frame 2 to allow the preloader in frame 1 to run. I'm trying to find out if there is a way to make the assets in the sound.swf to also load on frame2.

1
I don't really understand the question...blue112
It is much more practical to have two files: one preloader and one main movie. Preloading in the same file can give you problems (see this one). Is this for a banner or something where restrictions apply?Fygo
Yes. I am restricted to 1 file.Dave

1 Answers

0
votes

This seems to solve the issue for me. Sample code below. I embed a swf containing sound assets, but use "application/octet-stream" for the mimeType. Then later I can "load" the swf using the ActionScript Loader class. A symbol in the loaded swf can then be instantiated using "getDefinitionByName". Also, you can instantiate using "getDefinition" if you have a reference to the loaded swf, see the commented out line below. So far this works for me.

package
{
    import flash.display.Loader;
    import flash.display.MovieClip;
    import flash.media.Sound;
    import flash.events.Event;
    import flash.system.LoaderContext;
    import flash.system.ApplicationDomain;
    import flash.utils.getDefinitionByName;

    public class TestEmbed extends MovieClip
    {
        [Embed(source="EmbedAudio.swf", mimeType="application/octet-stream")]
        public var EmbedAudio : Class;
        public function TestEmbed()
        {
            super();

            // load embed swf
            var context : LoaderContext = new LoaderContext (false,ApplicationDomain.currentDomain);
            context.allowCodeImport = true;
            var loader : Loader = new Loader ();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
            loader.loadBytes (new EmbedAudio (), context);

        }

        private function loader_complete(evt:Event):void {
            // instantiate the class
            /*var ClassDefinition:Class = evt.target.applicationDomain.getDefinition("k3n1_01") as Class;*/
            var ClassDefinition:Class=getDefinitionByName("k3n1_01") as Class;
            var k3n1_01:Sound = new ClassDefinition();
            k3n1_01.play();
        }
    }
}