haXe Forum > Load other flash swf dynamically

  • Hey,

    I searched for preloaders and dynamic loading, and after literally days of searching the internet, I could not find answers. I apologise if there is a solution i overlooked.

    I am trying to create a method to load other swf's dynamically from my main class. I understand that preloaders don't work either, and was wondering if there is an easier way to have multiple flash videos loaded in my haxe project.

    Here's a simple quick example I made:

    package ;
    
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.Lib;
    import flash.display.Loader;
    import flash.events.KeyboardEvent;
    import flash.net.URLRequest;
    import flash.text.TextField;
    import flash.text.TextFieldType;
    import flash.events.IOErrorEvent;
    
    class Main extends Sprite
    {
        private var textInstructions:TextField;
        private var textInput:TextField;
        private var loader:Loader;
        private var URL:URLRequest;
        
        
        function new()
        {
            super();
            textInstructions = new TextField();
            textInstructions.x = textInstructions.y = 10;
            textInstructions.text = "Enter swf to load:  ";
            addChild(textInstructions);
            
            textInput = new TextField();
            textInput.x = textInstructions.x + textInstructions.width;
            textInput.y = textInstructions.y;
            textInput.width = 100;
            textInput.height = 50;
            textInput.type = TextFieldType.INPUT;
            addChild(textInput);
            
            loader = new Loader();
            addChild(loader);
            
            
            addEventListener(KeyboardEvent.KEY_DOWN, hitEnter);
            
        }
        
        function hitEnter(event:KeyboardEvent)
        {
            if (event.keyCode == 13 && textInput.text != "")
            {
                URL = new URLRequest(textInput.text);
                loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, Error);
                loader.contentLoaderInfo.addEventListener(Event.COMPLETE, Complete);
                loader.load(URL);
            }
        }
        
        function Error(event:IOErrorEvent)
        {
            trace(event.text);
        }
        
        function Complete(event:Event)
        {
            trace("Complete");
            addChild(loader.content); //This is where the problem is
        }
        
        static function main() 
        {
            var main = new Main();
            Lib.current.addChild(main);
        }
        
    }
    

    In this code, it allows someone to type in a local swf, then it should run it. Instead, it does nothing. Can someone help me out, or give me an alternative? This would be a huge help.

    Thanks
    Sinbu

  • Every haXe generated swf has the same document class(main entry point) : flash.Boot.
    If you load an swf that holds a class with the same name as already present in the parent, then that clas will be ignored and the existing class(in the parent) will be used. To prevent this you need to load the external swf into a seperate ApplicationDomain so it's (own) definitions are seperated from the definitions in the parent.
    http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/system/LoaderContext.html
    This is no different from regular 'AS3'. You cannot load a Flash CS4 swf with a document class called Main.as into another swf whose document class is also called Main.as

    Jan

  • But it is easy to load a flash created movie into haXe (same domain), in fact it's a very good way of getting your graphics in... otherwise Jan is correct.
    So advice use INIT event and specify a new Application Domain.

  • any chance of a tutorial?

  • First and foremost, thank you for the reply! I'll start testing it immediately. If someone can post a tutorial, that would be great, otherwise, when i get my example app running, ill post it here. Thanks again!

  • The class I use can be found here...
    SimpleLoader
    But really it's set up for either loading into a new Domain an image or animation or loading in flash IDE movie into the same domain for assets, I have another class not included for making it easy to use. I don't currently load haXe code movie into a haXe code movie often so don't have much code for talking between. What sort of tutorial are you looking for specifically?

  • would it be possible to import assets from sam haxe AND use the aswing library?

    I would use haxegui but utest wont install on haxelib, it says "unexpected element" on windows

  • Gershon is often on IRC and maybe able to help with haxegui setup. Sam is not yet setup for mac so I don't use it. But I think the idea is you create an asset swf that you use as a library for your haXe movie... I am guessing something along the lines of
    -swf-lib asset.swf
    so it should work fine with any flash haxe framework, but you may need to read the Sam manual for full details.

  • you cant import 2 libraries unfortunetly, so I will have to try to talk to gershon

  • the latest version of haxe (with haxelib) fixes the issue :)

< Prev | Page 1 / 1 | Next >