Haxe Game Development: Call for Article Request

classic Classic list List threaded Threaded
34 messages Options
12
Reply | Threaded
Open this post in threaded view
|

How to load another SWF in 2.03-2.04 ?

Kastellanos Nikos
I have the following simple app that I use as a preloader.
This worked perfectly fine until recently when compiled with the parameter
'-main Preloader',
but with 2.04  I get this error:

TypeError: Error #1009: Cannot access a property or method of a null object
reference.
        at Preloader$/main()[J:\development\AIA
Microsite\Preloader\src/Preloader.hx:31]
        at MethodInfo-68()[<null>:1]
        at flash::Boot()[C:\Program
Files\Motion-Twin\haxe/std/flash9/Boot.hx:86]  

This is also the case with 2.03. When I moved back to 2.02 it worked.
I guess something changed with the boot loader but I don't know the exact
details.
How can I load an SWF from inside another one?
 It looks like the Preloader::main() gets called initially,
 it starts loading the second SWF (for a few seconds I can see the custom
progress bar) and
 when the second SWF get's loaded, the Preloader::main() get's called again
for a second time!
That's when cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters throws
the #1009 error.

 



The source:
/**
* ...
* @author Kastellanos Nikos
*/
package ;

import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.Lib;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;




class Preloader
{
        var myLoader:Loader;
        var bar:MovieClip;
        var preloadBar:PreloadBar;

        static function main()
        {
                var src:String = "test.swf";
                var params:Dynamic<String> =
cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters; //Line 31
                src = (params.src==null)?src:params.src;
                var preloader:Preloader = new Preloader(src);
        }
       
        public function new(filename)
        {
                myLoader = new Loader();
                var myRequest:URLRequest = new URLRequest(filename);

                var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
                myLoader.load(myRequest,ldrContext);
               
       
myLoader.contentLoaderInfo.addEventListener(Event.OPEN,onOpen);
       
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgres
s);
                myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
onComplete);
                Lib.current.addChild(myLoader);
                myLoader.visible = false;
                return;
        }
       
        function onOpen(evt:Event):Void
        {
                preloadBar = new PreloadBar();
                Lib.current.addChild(preloadBar);
                preloadBar.x = (Lib.current.stage.stageWidth -
preloadBar.width)/2;
                preloadBar.y = (Lib.current.stage.stageHeight -
preloadBar.height) / 2;
        }

        function onProgress(evt:ProgressEvent):Void
        {
                var ptc:Float = evt.bytesLoaded / evt.bytesTotal;

                if (evt.bytesLoaded == evt.bytesTotal)
                {
                        flash.Lib.current.removeChild(preloadBar);
                }
                preloadBar.iBar.scaleX = ptc;
        }
       
        function onComplete(evt:Event):Void
        {
                var loader:Loader = evt.target.loader;
        var info:LoaderInfo = loader.contentLoaderInfo;
                myLoader.visible = true;
        }
}


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: How to load another SWF in 2.03-2.04 ?

jlm@justinfront.net
Unfortunately since 2.03 you can only use loaded haXe swf from a  
separate Application Domain ( you can load mxml/flash swf's into same  
domain so I would imagine there might be a workround using flex sdk  
and a haXe SWC ), this is due to boot clashes or something more  
complex, I presume Nicolas is still pondering a better solution.

Cheers

;j


On 7 Oct 2009, at 14:38, Kastellanos Nikos wrote:

> I have the following simple app that I use as a preloader.
> This worked perfectly fine until recently when compiled with the  
> parameter
> '-main Preloader',
> but with 2.04  I get this error:
>
> TypeError: Error #1009: Cannot access a property or method of a null  
> object
> reference.
> at Preloader$/main()[J:\development\AIA
> Microsite\Preloader\src/Preloader.hx:31]
> at MethodInfo-68()[<null>:1]
> at flash::Boot()[C:\Program
> Files\Motion-Twin\haxe/std/flash9/Boot.hx:86]
>
> This is also the case with 2.03. When I moved back to 2.02 it worked.
> I guess something changed with the boot loader but I don't know the  
> exact
> details.
> How can I load an SWF from inside another one?
> It looks like the Preloader::main() gets called initially,
> it starts loading the second SWF (for a few seconds I can see the  
> custom
> progress bar) and
> when the second SWF get's loaded, the Preloader::main() get's called  
> again
> for a second time!
> That's when cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters  
> throws
> the #1009 error.
>
>
>
>
>
> The source:
> /**
> * ...
> * @author Kastellanos Nikos
> */
> package ;
>
> import flash.display.DisplayObject;
> import flash.display.MovieClip;
> import flash.display.Stage;
> import flash.Lib;
> import flash.display.Loader;
> import flash.display.LoaderInfo;
> import flash.net.URLRequest;
> import flash.events.Event;
> import flash.events.ProgressEvent;
> import flash.system.ApplicationDomain;
> import flash.system.LoaderContext;
>
>
>
>
> class Preloader
> {
> var myLoader:Loader;
> var bar:MovieClip;
> var preloadBar:PreloadBar;
>
> static function main()
> {
> var src:String = "test.swf";
> var params:Dynamic<String> =
> cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters; //Line 31
> src = (params.src==null)?src:params.src;
> var preloader:Preloader = new Preloader(src);
> }
>
> public function new(filename)
> {
> myLoader = new Loader();
> var myRequest:URLRequest = new URLRequest(filename);
>
> var ldrContext:LoaderContext = new LoaderContext(false,
> ApplicationDomain.currentDomain);
> myLoader.load(myRequest,ldrContext);
>
>
> myLoader.contentLoaderInfo.addEventListener(Event.OPEN,onOpen);
>
> myLoader
> .contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgres
> s);
> myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
> onComplete);
> Lib.current.addChild(myLoader);
> myLoader.visible = false;
> return;
> }
>
> function onOpen(evt:Event):Void
> {
> preloadBar = new PreloadBar();
> Lib.current.addChild(preloadBar);
> preloadBar.x = (Lib.current.stage.stageWidth -
> preloadBar.width)/2;
> preloadBar.y = (Lib.current.stage.stageHeight -
> preloadBar.height) / 2;
> }
>
> function onProgress(evt:ProgressEvent):Void
> {
> var ptc:Float = evt.bytesLoaded / evt.bytesTotal;
>
> if (evt.bytesLoaded == evt.bytesTotal)
> {
> flash.Lib.current.removeChild(preloadBar);
> }
> preloadBar.iBar.scaleX = ptc;
> }
>
> function onComplete(evt:Event):Void
> {
> var loader:Loader = evt.target.loader;
>        var info:LoaderInfo = loader.contentLoaderInfo;
> myLoader.visible = true;
> }
> }
>
>
> --
> haXe - an open source web programming language
> http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: How to load another SWF in 2.03-2.04 ?

jlm@justinfront.net
It is possible to setup communication with a separate Application  
Domain, I suspect the main issue is you may loose compile time type  
safety.

Cheers

;j

On 7 Oct 2009, at 14:45, Justin Lawerance Mills wrote:

> Unfortunately since 2.03 you can only use loaded haXe swf from a  
> separate Application Domain ( you can load mxml/flash swf's into  
> same domain so I would imagine there might be a workround using flex  
> sdk and a haXe SWC ), this is due to boot clashes or something more  
> complex, I presume Nicolas is still pondering a better solution.
>
> Cheers
>
> ;j
>
>
> On 7 Oct 2009, at 14:38, Kastellanos Nikos wrote:
>
>> I have the following simple app that I use as a preloader.
>> This worked perfectly fine until recently when compiled with the  
>> parameter
>> '-main Preloader',
>> but with 2.04  I get this error:
>>
>> TypeError: Error #1009: Cannot access a property or method of a  
>> null object
>> reference.
>> at Preloader$/main()[J:\development\AIA
>> Microsite\Preloader\src/Preloader.hx:31]
>> at MethodInfo-68()[<null>:1]
>> at flash::Boot()[C:\Program
>> Files\Motion-Twin\haxe/std/flash9/Boot.hx:86]
>>
>> This is also the case with 2.03. When I moved back to 2.02 it worked.
>> I guess something changed with the boot loader but I don't know the  
>> exact
>> details.
>> How can I load an SWF from inside another one?
>> It looks like the Preloader::main() gets called initially,
>> it starts loading the second SWF (for a few seconds I can see the  
>> custom
>> progress bar) and
>> when the second SWF get's loaded, the Preloader::main() get's  
>> called again
>> for a second time!
>> That's when  
>> cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters throws
>> the #1009 error.
>>
>>
>>
>>
>>
>> The source:
>> /**
>> * ...
>> * @author Kastellanos Nikos
>> */
>> package ;
>>
>> import flash.display.DisplayObject;
>> import flash.display.MovieClip;
>> import flash.display.Stage;
>> import flash.Lib;
>> import flash.display.Loader;
>> import flash.display.LoaderInfo;
>> import flash.net.URLRequest;
>> import flash.events.Event;
>> import flash.events.ProgressEvent;
>> import flash.system.ApplicationDomain;
>> import flash.system.LoaderContext;
>>
>>
>>
>>
>> class Preloader
>> {
>> var myLoader:Loader;
>> var bar:MovieClip;
>> var preloadBar:PreloadBar;
>>
>> static function main()
>> {
>> var src:String = "test.swf";
>> var params:Dynamic<String> =
>> cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters; //Line 31
>> src = (params.src==null)?src:params.src;
>> var preloader:Preloader = new Preloader(src);
>> }
>>
>> public function new(filename)
>> {
>> myLoader = new Loader();
>> var myRequest:URLRequest = new URLRequest(filename);
>>
>> var ldrContext:LoaderContext = new LoaderContext(false,
>> ApplicationDomain.currentDomain);
>> myLoader.load(myRequest,ldrContext);
>>
>>
>> myLoader.contentLoaderInfo.addEventListener(Event.OPEN,onOpen);
>>
>> myLoader
>> .contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgres
>> s);
>> myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
>> onComplete);
>> Lib.current.addChild(myLoader);
>> myLoader.visible = false;
>> return;
>> }
>>
>> function onOpen(evt:Event):Void
>> {
>> preloadBar = new PreloadBar();
>> Lib.current.addChild(preloadBar);
>> preloadBar.x = (Lib.current.stage.stageWidth -
>> preloadBar.width)/2;
>> preloadBar.y = (Lib.current.stage.stageHeight -
>> preloadBar.height) / 2;
>> }
>>
>> function onProgress(evt:ProgressEvent):Void
>> {
>> var ptc:Float = evt.bytesLoaded / evt.bytesTotal;
>>
>> if (evt.bytesLoaded == evt.bytesTotal)
>> {
>> flash.Lib.current.removeChild(preloadBar);
>> }
>> preloadBar.iBar.scaleX = ptc;
>> }
>>
>> function onComplete(evt:Event):Void
>> {
>> var loader:Loader = evt.target.loader;
>>       var info:LoaderInfo = loader.contentLoaderInfo;
>> myLoader.visible = true;
>> }
>> }
>>
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
>
> --
> haXe - an open source web programming language
> http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

RE: How to load another SWF in 2.03-2.04 ?

Kastellanos Nikos
In reply to this post by Laurent Kappler
OK, I just found that I had to load it in a new Application Domain.
Replace line : var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
with: var ldrContext:LoaderContext = new LoaderContext(false, new
ApplicationDomain());



---------------------------------------
I have the following simple app that I use as a preloader.
This worked perfectly fine until recently when compiled with the parameter
'-main Preloader',
but with 2.04  I get this error:

TypeError: Error #1009: Cannot access a property or method of a null object
reference.
        at Preloader$/main()[J:\development\AIA
Microsite\Preloader\src/Preloader.hx:31]
        at MethodInfo-68()[<null>:1]
        at flash::Boot()[C:\Program
Files\Motion-Twin\haxe/std/flash9/Boot.hx:86]  

This is also the case with 2.03. When I moved back to 2.02 it worked.
I guess something changed with the boot loader but I don't know the exact
details.
How can I load an SWF from inside another one?
 It looks like the Preloader::main() gets called initially,
 it starts loading the second SWF (for a few seconds I can see the custom
progress bar) and
 when the second SWF get's loaded, the Preloader::main() get's called again
for a second time!
That's when cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters throws
the #1009 error.

 



The source:
/**
* ...
* @author Kastellanos Nikos
*/
package ;

import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.Lib;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;




class Preloader
{
        var myLoader:Loader;
        var bar:MovieClip;
        var preloadBar:PreloadBar;

        static function main()
        {
                var src:String = "test.swf";
                var params:Dynamic<String> =
cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters; //Line 31
                src = (params.src==null)?src:params.src;
                var preloader:Preloader = new Preloader(src);
        }
       
        public function new(filename)
        {
                myLoader = new Loader();
                var myRequest:URLRequest = new URLRequest(filename);

                var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
                myLoader.load(myRequest,ldrContext);
               
       
myLoader.contentLoaderInfo.addEventListener(Event.OPEN,onOpen);
       
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgres
s);
                myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
onComplete);
                Lib.current.addChild(myLoader);
                myLoader.visible = false;
                return;
        }
       
        function onOpen(evt:Event):Void
        {
                preloadBar = new PreloadBar();
                Lib.current.addChild(preloadBar);
                preloadBar.x = (Lib.current.stage.stageWidth -
preloadBar.width)/2;
                preloadBar.y = (Lib.current.stage.stageHeight -
preloadBar.height) / 2;
        }

        function onProgress(evt:ProgressEvent):Void
        {
                var ptc:Float = evt.bytesLoaded / evt.bytesTotal;

                if (evt.bytesLoaded == evt.bytesTotal)
                {
                        flash.Lib.current.removeChild(preloadBar);
                }
                preloadBar.iBar.scaleX = ptc;
        }
       
        function onComplete(evt:Event):Void
        {
                var loader:Loader = evt.target.loader;
        var info:LoaderInfo = loader.contentLoaderInfo;
                myLoader.visible = true;
        }
}


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: RE: How to load another SWF in 2.03-2.04 ?

gershon
i'm doing something similar and have a question...
Got a class, called XmlEditor, in which i load swfs into a new application domain (new LoaderContext(false, new ApplicationDomain()))
Those swf are compiled from classes which extend the base EditorPlugin class, which conforms to an interface, IEditorPlugin.

here's some code for that:

//{{{ IEditorPlugin
interface IEditorPlugin {
    public var url : String;

    public function start() : Void;
    public function run() : Void;
    public function redraw() : Void;
}
//}}}


//{{{ EditorPlugin
class EditorPlugin implements IEditorPlugin {
    public var url : String;

    public var editor : XmlEditor;
    public var console : Console;

    public function new(?url:String=null) {
        if(url==null)
        url = Type.getClassName(Type.getClass(this)) + ".swf";
    }

    public function toString() : String {
        return "["+Type.getClassName(Type.getClass(this))+"]"+url;
    }

    public function start()  {}
    public function run()    {}
    public function redraw() {}

}
//}}}

so a plugin looks something like:

//{{{ WhiteSpacePlugin
/**
* Visualizes whitespace
*/
class WhiteSpacePlugin extends EditorPlugin {

    public static function main() {
    }

    public override function start() {
        console.log("Starting WhiteSpace Plugin...");
    }
.....
..
.
//}}}

i was thinking the being based on an interface there'll be no problem calling those functions, but it does'nt seem to work...
should i be messing around with getDefinition() ? am i loading in the wrong application domain ?



On Wed, Oct 7, 2009 at 3:50 PM, Kastellanos Nikos <[hidden email]> wrote:
OK, I just found that I had to load it in a new Application Domain.
Replace line : var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
with: var ldrContext:LoaderContext = new LoaderContext(false, new
ApplicationDomain());



---------------------------------------
I have the following simple app that I use as a preloader.
This worked perfectly fine until recently when compiled with the parameter
'-main Preloader',
but with 2.04  I get this error:

TypeError: Error #1009: Cannot access a property or method of a null object
reference.
       at Preloader$/main()[J:\development\AIA
Microsite\Preloader\src/Preloader.hx:31]
       at MethodInfo-68()[<null>:1]
       at flash::Boot()[C:\Program
Files\Motion-Twin\haxe/std/flash9/Boot.hx:86]

This is also the case with 2.03. When I moved back to 2.02 it worked.
I guess something changed with the boot loader but I don't know the exact
details.
How can I load an SWF from inside another one?
 It looks like the Preloader::main() gets called initially,
 it starts loading the second SWF (for a few seconds I can see the custom
progress bar) and
 when the second SWF get's loaded, the Preloader::main() get's called again
for a second time!
That's when cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters throws
the #1009 error.





The source:
/**
* ...
* @author Kastellanos Nikos
*/
package ;

import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.Lib;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;




class Preloader
{
       var myLoader:Loader;
       var bar:MovieClip;
       var preloadBar:PreloadBar;

       static function main()
       {
               var src:String = "test.swf";
               var params:Dynamic<String> =
cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters; //Line 31
               src = (params.src==null)?src:params.src;
               var preloader:Preloader = new Preloader(src);
       }

       public function new(filename)
       {
               myLoader = new Loader();
               var myRequest:URLRequest = new URLRequest(filename);

               var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
               myLoader.load(myRequest,ldrContext);


myLoader.contentLoaderInfo.addEventListener(Event.OPEN,onOpen);

myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgres
s);
               myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
onComplete);
               Lib.current.addChild(myLoader);
               myLoader.visible = false;
               return;
       }

       function onOpen(evt:Event):Void
       {
               preloadBar = new PreloadBar();
               Lib.current.addChild(preloadBar);
               preloadBar.x = (Lib.current.stage.stageWidth -
preloadBar.width)/2;
               preloadBar.y = (Lib.current.stage.stageHeight -
preloadBar.height) / 2;
       }

       function onProgress(evt:ProgressEvent):Void
       {
               var ptc:Float = evt.bytesLoaded / evt.bytesTotal;

               if (evt.bytesLoaded == evt.bytesTotal)
               {
                       flash.Lib.current.removeChild(preloadBar);
               }
               preloadBar.iBar.scaleX = ptc;
       }

       function onComplete(evt:Event):Void
       {
               var loader:Loader = evt.target.loader;
       var info:LoaderInfo = loader.contentLoaderInfo;
               myLoader.visible = true;
       }
}


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: RE: How to load another SWF in 2.03-2.04 ?

jlm@justinfront.net
Gershon

I have been loading haXe into flash movie but I changed below to cast so should be ok may need some tweaking

class EditorPlugin extends MovieClip{ ... }
...
public static var _this: WhiteSpacePlugin;
static function main(){ _this = new WhiteSpacePlugin(); }
public function new(){ super(); }
...
var app: ApplicationDomain = _loader.contentLoaderInfo.applicationDomain;
var whiteSpacePlugin: MovieClip = cast( app.getDefinition("SiteMain")._this, MovieClip );

//To setup listeners say if your passing on loader data of some external loaded assets

var externalEventInstance:Dynamic = whiteSpacePlugin.getSimpleLoadEventInstance();
var simpleLoadEvent: Class = app.getDefinition(getQualifiedClassName( externalEventInstance )) as Class;
whiteSpacePlugin.addEventListener( simpleLoadEvent.PROGRESS,    externalProgress   );
     whiteSpacePlugin.addEventListener( simpleLoadEvent.COMPLETED,   externalFinish      );

whiteSpacePlugin.start();


Left a few gaps and it may not be idea solution, but I fairly sure interfaces will not help in flash or haxe.  ( Ps if your using stageWidth in the loaded movie make sure you wait till its resolved )

Cheers

;j


On 8 Oct 2009, at 04:37, gershon wrote:

i'm doing something similar and have a question...
Got a class, called XmlEditor, in which i load swfs into a new application domain (new LoaderContext(false, new ApplicationDomain()))
Those swf are compiled from classes which extend the base EditorPlugin class, which conforms to an interface, IEditorPlugin.

here's some code for that:

//{{{ IEditorPlugin
interface IEditorPlugin {
    public var url : String;

    public function start() : Void;
    public function run() : Void;
    public function redraw() : Void;
}
//}}}


//{{{ EditorPlugin
class EditorPlugin implements IEditorPlugin {
    public var url : String;

    public var editor : XmlEditor;
    public var console : Console;

    public function new(?url:String=null) {
        if(url==null)
        url = Type.getClassName(Type.getClass(this)) + ".swf";
    }

    public function toString() : String {
        return "["+Type.getClassName(Type.getClass(this))+"]"+url;
    }

    public function start()  {}
    public function run()    {}
    public function redraw() {}

}
//}}}

so a plugin looks something like:

//{{{ WhiteSpacePlugin
/**
* Visualizes whitespace
*/
class WhiteSpacePlugin extends EditorPlugin {

    public static function main() {
    }

    public override function start() {
        console.log("Starting WhiteSpace Plugin...");
    }
.....
..
.
//}}}

i was thinking the being based on an interface there'll be no problem calling those functions, but it does'nt seem to work...
should i be messing around with getDefinition() ? am i loading in the wrong application domain ?



On Wed, Oct 7, 2009 at 3:50 PM, Kastellanos Nikos <[hidden email]> wrote:
OK, I just found that I had to load it in a new Application Domain.
Replace line : var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
with: var ldrContext:LoaderContext = new LoaderContext(false, new
ApplicationDomain());



---------------------------------------
I have the following simple app that I use as a preloader.
This worked perfectly fine until recently when compiled with the parameter
'-main Preloader',
but with 2.04  I get this error:

TypeError: Error #1009: Cannot access a property or method of a null object
reference.
       at Preloader$/main()[J:\development\AIA
Microsite\Preloader\src/Preloader.hx:31]
       at MethodInfo-68()[<null>:1]
       at flash::Boot()[C:\Program
Files\Motion-Twin\haxe/std/flash9/Boot.hx:86]

This is also the case with 2.03. When I moved back to 2.02 it worked.
I guess something changed with the boot loader but I don't know the exact
details.
How can I load an SWF from inside another one?
 It looks like the Preloader::main() gets called initially,
 it starts loading the second SWF (for a few seconds I can see the custom
progress bar) and
 when the second SWF get's loaded, the Preloader::main() get's called again
for a second time!
That's when cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters throws
the #1009 error.





The source:
/**
* ...
* @author Kastellanos Nikos
*/
package ;

import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.Lib;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;




class Preloader
{
       var myLoader:Loader;
       var bar:MovieClip;
       var preloadBar:PreloadBar;

       static function main()
       {
               var src:String = "test.swf";
               var params:Dynamic<String> =
cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters; //Line 31
               src = (params.src==null)?src:params.src;
               var preloader:Preloader = new Preloader(src);
       }

       public function new(filename)
       {
               myLoader = new Loader();
               var myRequest:URLRequest = new URLRequest(filename);

               var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
               myLoader.load(myRequest,ldrContext);


myLoader.contentLoaderInfo.addEventListener(Event.OPEN,onOpen);

myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgres
s);
               myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
onComplete);
               Lib.current.addChild(myLoader);
               myLoader.visible = false;
               return;
       }

       function onOpen(evt:Event):Void
       {
               preloadBar = new PreloadBar();
               Lib.current.addChild(preloadBar);
               preloadBar.x = (Lib.current.stage.stageWidth -
preloadBar.width)/2;
               preloadBar.y = (Lib.current.stage.stageHeight -
preloadBar.height) / 2;
       }

       function onProgress(evt:ProgressEvent):Void
       {
               var ptc:Float = evt.bytesLoaded / evt.bytesTotal;

               if (evt.bytesLoaded == evt.bytesTotal)
               {
                       flash.Lib.current.removeChild(preloadBar);
               }
               preloadBar.iBar.scaleX = ptc;
       }

       function onComplete(evt:Event):Void
       {
               var loader:Loader = evt.target.loader;
       var info:LoaderInfo = loader.contentLoaderInfo;
               myLoader.visible = true;
       }
}


--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: RE: How to load another SWF in 2.03-2.04 ?

jlm@justinfront.net
OOPs typo...

var whiteSpacePlugin: MovieClip = cast( app.getDefinition("SiteMain")._this, MovieClip );

should be

var whiteSpacePlugin: MovieClip = cast( app.getDefinition("WhiteSpacePlugin")._this, MovieClip );


On 8 Oct 2009, at 06:50, Justin Lawerance Mills wrote:

Gershon

I have been loading haXe into flash movie but I changed below to cast so should be ok may need some tweaking

class EditorPlugin extends MovieClip{ ... }
...
public static var _this: WhiteSpacePlugin;
static function main(){ _this = new WhiteSpacePlugin(); }
public function new(){ super(); }
...
var app: ApplicationDomain = _loader.contentLoaderInfo.applicationDomain;
var whiteSpacePlugin: MovieClip = cast( app.getDefinition("SiteMain")._this, MovieClip );

//To setup listeners say if your passing on loader data of some external loaded assets

var externalEventInstance:Dynamic = whiteSpacePlugin.getSimpleLoadEventInstance();
var simpleLoadEvent: Class = app.getDefinition(getQualifiedClassName( externalEventInstance )) as Class;
whiteSpacePlugin.addEventListener( simpleLoadEvent.PROGRESS,    externalProgress   );
     whiteSpacePlugin.addEventListener( simpleLoadEvent.COMPLETED,   externalFinish      );

whiteSpacePlugin.start();


Left a few gaps and it may not be idea solution, but I fairly sure interfaces will not help in flash or haxe.  ( Ps if your using stageWidth in the loaded movie make sure you wait till its resolved )

Cheers

;j


On 8 Oct 2009, at 04:37, gershon wrote:

i'm doing something similar and have a question...
Got a class, called XmlEditor, in which i load swfs into a new application domain (new LoaderContext(false, new ApplicationDomain()))
Those swf are compiled from classes which extend the base EditorPlugin class, which conforms to an interface, IEditorPlugin.

here's some code for that:

//{{{ IEditorPlugin
interface IEditorPlugin {
    public var url : String;

    public function start() : Void;
    public function run() : Void;
    public function redraw() : Void;
}
//}}}


//{{{ EditorPlugin
class EditorPlugin implements IEditorPlugin {
    public var url : String;

    public var editor : XmlEditor;
    public var console : Console;

    public function new(?url:String=null) {
        if(url==null)
        url = Type.getClassName(Type.getClass(this)) + ".swf";
    }

    public function toString() : String {
        return "["+Type.getClassName(Type.getClass(this))+"]"+url;
    }

    public function start()  {}
    public function run()    {}
    public function redraw() {}

}
//}}}

so a plugin looks something like:

//{{{ WhiteSpacePlugin
/**
* Visualizes whitespace
*/
class WhiteSpacePlugin extends EditorPlugin {

    public static function main() {
    }

    public override function start() {
        console.log("Starting WhiteSpace Plugin...");
    }
.....
..
.
//}}}

i was thinking the being based on an interface there'll be no problem calling those functions, but it does'nt seem to work...
should i be messing around with getDefinition() ? am i loading in the wrong application domain ?



On Wed, Oct 7, 2009 at 3:50 PM, Kastellanos Nikos <[hidden email]> wrote:
OK, I just found that I had to load it in a new Application Domain.
Replace line : var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
with: var ldrContext:LoaderContext = new LoaderContext(false, new
ApplicationDomain());



---------------------------------------
I have the following simple app that I use as a preloader.
This worked perfectly fine until recently when compiled with the parameter
'-main Preloader',
but with 2.04  I get this error:

TypeError: Error #1009: Cannot access a property or method of a null object
reference.
       at Preloader$/main()[J:\development\AIA
Microsite\Preloader\src/Preloader.hx:31]
       at MethodInfo-68()[<null>:1]
       at flash::Boot()[C:\Program
Files\Motion-Twin\haxe/std/flash9/Boot.hx:86]

This is also the case with 2.03. When I moved back to 2.02 it worked.
I guess something changed with the boot loader but I don't know the exact
details.
How can I load an SWF from inside another one?
 It looks like the Preloader::main() gets called initially,
 it starts loading the second SWF (for a few seconds I can see the custom
progress bar) and
 when the second SWF get's loaded, the Preloader::main() get's called again
for a second time!
That's when cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters throws
the #1009 error.





The source:
/**
* ...
* @author Kastellanos Nikos
*/
package ;

import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.Lib;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;




class Preloader
{
       var myLoader:Loader;
       var bar:MovieClip;
       var preloadBar:PreloadBar;

       static function main()
       {
               var src:String = "test.swf";
               var params:Dynamic<String> =
cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters; //Line 31
               src = (params.src==null)?src:params.src;
               var preloader:Preloader = new Preloader(src);
       }

       public function new(filename)
       {
               myLoader = new Loader();
               var myRequest:URLRequest = new URLRequest(filename);

               var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
               myLoader.load(myRequest,ldrContext);


myLoader.contentLoaderInfo.addEventListener(Event.OPEN,onOpen);

myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgres
s);
               myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
onComplete);
               Lib.current.addChild(myLoader);
               myLoader.visible = false;
               return;
       }

       function onOpen(evt:Event):Void
       {
               preloadBar = new PreloadBar();
               Lib.current.addChild(preloadBar);
               preloadBar.x = (Lib.current.stage.stageWidth -
preloadBar.width)/2;
               preloadBar.y = (Lib.current.stage.stageHeight -
preloadBar.height) / 2;
       }

       function onProgress(evt:ProgressEvent):Void
       {
               var ptc:Float = evt.bytesLoaded / evt.bytesTotal;

               if (evt.bytesLoaded == evt.bytesTotal)
               {
                       flash.Lib.current.removeChild(preloadBar);
               }
               preloadBar.iBar.scaleX = ptc;
       }

       function onComplete(evt:Event):Void
       {
               var loader:Loader = evt.target.loader;
       var info:LoaderInfo = loader.contentLoaderInfo;
               myLoader.visible = true;
       }
}


--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: RE: How to load another SWF in 2.03-2.04 ?

jlm@justinfront.net
As you prob realize from our irc chats I was loading haXe into flash preloader separate domain and loading flash graphics into haXe same domain hence the passing on of loaded data.

On 8 Oct 2009, at 06:54, Justin Lawerance Mills wrote:

OOPs typo...

var whiteSpacePlugin: MovieClip = cast( app.getDefinition("SiteMain")._this, MovieClip );

should be

var whiteSpacePlugin: MovieClip = cast( app.getDefinition("WhiteSpacePlugin")._this, MovieClip );


On 8 Oct 2009, at 06:50, Justin Lawerance Mills wrote:

Gershon

I have been loading haXe into flash movie but I changed below to cast so should be ok may need some tweaking

class EditorPlugin extends MovieClip{ ... }
...
public static var _this: WhiteSpacePlugin;
static function main(){ _this = new WhiteSpacePlugin(); }
public function new(){ super(); }
...
var app: ApplicationDomain = _loader.contentLoaderInfo.applicationDomain;
var whiteSpacePlugin: MovieClip = cast( app.getDefinition("SiteMain")._this, MovieClip );

//To setup listeners say if your passing on loader data of some external loaded assets

var externalEventInstance:Dynamic = whiteSpacePlugin.getSimpleLoadEventInstance();
var simpleLoadEvent: Class = app.getDefinition(getQualifiedClassName( externalEventInstance )) as Class;
whiteSpacePlugin.addEventListener( simpleLoadEvent.PROGRESS,    externalProgress   );
     whiteSpacePlugin.addEventListener( simpleLoadEvent.COMPLETED,   externalFinish      );

whiteSpacePlugin.start();


Left a few gaps and it may not be idea solution, but I fairly sure interfaces will not help in flash or haxe.  ( Ps if your using stageWidth in the loaded movie make sure you wait till its resolved )

Cheers

;j


On 8 Oct 2009, at 04:37, gershon wrote:

i'm doing something similar and have a question...
Got a class, called XmlEditor, in which i load swfs into a new application domain (new LoaderContext(false, new ApplicationDomain()))
Those swf are compiled from classes which extend the base EditorPlugin class, which conforms to an interface, IEditorPlugin.

here's some code for that:

//{{{ IEditorPlugin
interface IEditorPlugin {
    public var url : String;

    public function start() : Void;
    public function run() : Void;
    public function redraw() : Void;
}
//}}}


//{{{ EditorPlugin
class EditorPlugin implements IEditorPlugin {
    public var url : String;

    public var editor : XmlEditor;
    public var console : Console;

    public function new(?url:String=null) {
        if(url==null)
        url = Type.getClassName(Type.getClass(this)) + ".swf";
    }

    public function toString() : String {
        return "["+Type.getClassName(Type.getClass(this))+"]"+url;
    }

    public function start()  {}
    public function run()    {}
    public function redraw() {}

}
//}}}

so a plugin looks something like:

//{{{ WhiteSpacePlugin
/**
* Visualizes whitespace
*/
class WhiteSpacePlugin extends EditorPlugin {

    public static function main() {
    }

    public override function start() {
        console.log("Starting WhiteSpace Plugin...");
    }
.....
..
.
//}}}

i was thinking the being based on an interface there'll be no problem calling those functions, but it does'nt seem to work...
should i be messing around with getDefinition() ? am i loading in the wrong application domain ?



On Wed, Oct 7, 2009 at 3:50 PM, Kastellanos Nikos <[hidden email]> wrote:
OK, I just found that I had to load it in a new Application Domain.
Replace line : var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
with: var ldrContext:LoaderContext = new LoaderContext(false, new
ApplicationDomain());



---------------------------------------
I have the following simple app that I use as a preloader.
This worked perfectly fine until recently when compiled with the parameter
'-main Preloader',
but with 2.04  I get this error:

TypeError: Error #1009: Cannot access a property or method of a null object
reference.
       at Preloader$/main()[J:\development\AIA
Microsite\Preloader\src/Preloader.hx:31]
       at MethodInfo-68()[<null>:1]
       at flash::Boot()[C:\Program
Files\Motion-Twin\haxe/std/flash9/Boot.hx:86]

This is also the case with 2.03. When I moved back to 2.02 it worked.
I guess something changed with the boot loader but I don't know the exact
details.
How can I load an SWF from inside another one?
 It looks like the Preloader::main() gets called initially,
 it starts loading the second SWF (for a few seconds I can see the custom
progress bar) and
 when the second SWF get's loaded, the Preloader::main() get's called again
for a second time!
That's when cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters throws
the #1009 error.





The source:
/**
* ...
* @author Kastellanos Nikos
*/
package ;

import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.Lib;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;




class Preloader
{
       var myLoader:Loader;
       var bar:MovieClip;
       var preloadBar:PreloadBar;

       static function main()
       {
               var src:String = "test.swf";
               var params:Dynamic<String> =
cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters; //Line 31
               src = (params.src==null)?src:params.src;
               var preloader:Preloader = new Preloader(src);
       }

       public function new(filename)
       {
               myLoader = new Loader();
               var myRequest:URLRequest = new URLRequest(filename);

               var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
               myLoader.load(myRequest,ldrContext);


myLoader.contentLoaderInfo.addEventListener(Event.OPEN,onOpen);

myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgres
s);
               myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
onComplete);
               Lib.current.addChild(myLoader);
               myLoader.visible = false;
               return;
       }

       function onOpen(evt:Event):Void
       {
               preloadBar = new PreloadBar();
               Lib.current.addChild(preloadBar);
               preloadBar.x = (Lib.current.stage.stageWidth -
preloadBar.width)/2;
               preloadBar.y = (Lib.current.stage.stageHeight -
preloadBar.height) / 2;
       }

       function onProgress(evt:ProgressEvent):Void
       {
               var ptc:Float = evt.bytesLoaded / evt.bytesTotal;

               if (evt.bytesLoaded == evt.bytesTotal)
               {
                       flash.Lib.current.removeChild(preloadBar);
               }
               preloadBar.iBar.scaleX = ptc;
       }

       function onComplete(evt:Event):Void
       {
               var loader:Loader = evt.target.loader;
       var info:LoaderInfo = loader.contentLoaderInfo;
               myLoader.visible = true;
       }
}


--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: RE: How to load another SWF in 2.03-2.04 ?

jlm@justinfront.net
ps you will need this

addChild(loader.content);

before 

var app: ApplicationDomain = _loader.contentLoaderInfo.applicationDomain;
var whiteSpacePlugin: MovieClip = cast( app.getDefinition("WhiteSpacePlugin")._this, MovieClip );

you prob don't need to extend movieclip... but if your loading a swf its a sprite/movieclip really anyway and being dynamic movieclip allows you to call what you like on it without compiler checking, but I am guessing you were trying to avoid that with the interface...  seems optimistic, separate application destroy type safety by the nature of being separate. 

 Cheers

;j

On 8 Oct 2009, at 07:01, Justin Lawerance Mills wrote:

As you prob realize from our irc chats I was loading haXe into flash preloader separate domain and loading flash graphics into haXe same domain hence the passing on of loaded data.

On 8 Oct 2009, at 06:54, Justin Lawerance Mills wrote:

OOPs typo...

var whiteSpacePlugin: MovieClip = cast( app.getDefinition("SiteMain")._this, MovieClip );

should be

var whiteSpacePlugin: MovieClip = cast( app.getDefinition("WhiteSpacePlugin")._this, MovieClip );


On 8 Oct 2009, at 06:50, Justin Lawerance Mills wrote:

Gershon

I have been loading haXe into flash movie but I changed below to cast so should be ok may need some tweaking

class EditorPlugin extends MovieClip{ ... }
...
public static var _this: WhiteSpacePlugin;
static function main(){ _this = new WhiteSpacePlugin(); }
public function new(){ super(); }
...
var app: ApplicationDomain = _loader.contentLoaderInfo.applicationDomain;
var whiteSpacePlugin: MovieClip = cast( app.getDefinition("SiteMain")._this, MovieClip );

//To setup listeners say if your passing on loader data of some external loaded assets

var externalEventInstance:Dynamic = whiteSpacePlugin.getSimpleLoadEventInstance();
var simpleLoadEvent: Class = app.getDefinition(getQualifiedClassName( externalEventInstance )) as Class;
whiteSpacePlugin.addEventListener( simpleLoadEvent.PROGRESS,    externalProgress   );
     whiteSpacePlugin.addEventListener( simpleLoadEvent.COMPLETED,   externalFinish      );

whiteSpacePlugin.start();


Left a few gaps and it may not be idea solution, but I fairly sure interfaces will not help in flash or haxe.  ( Ps if your using stageWidth in the loaded movie make sure you wait till its resolved )

Cheers

;j


On 8 Oct 2009, at 04:37, gershon wrote:

i'm doing something similar and have a question...
Got a class, called XmlEditor, in which i load swfs into a new application domain (new LoaderContext(false, new ApplicationDomain()))
Those swf are compiled from classes which extend the base EditorPlugin class, which conforms to an interface, IEditorPlugin.

here's some code for that:

//{{{ IEditorPlugin
interface IEditorPlugin {
    public var url : String;

    public function start() : Void;
    public function run() : Void;
    public function redraw() : Void;
}
//}}}


//{{{ EditorPlugin
class EditorPlugin implements IEditorPlugin {
    public var url : String;

    public var editor : XmlEditor;
    public var console : Console;

    public function new(?url:String=null) {
        if(url==null)
        url = Type.getClassName(Type.getClass(this)) + ".swf";
    }

    public function toString() : String {
        return "["+Type.getClassName(Type.getClass(this))+"]"+url;
    }

    public function start()  {}
    public function run()    {}
    public function redraw() {}

}
//}}}

so a plugin looks something like:

//{{{ WhiteSpacePlugin
/**
* Visualizes whitespace
*/
class WhiteSpacePlugin extends EditorPlugin {

    public static function main() {
    }

    public override function start() {
        console.log("Starting WhiteSpace Plugin...");
    }
.....
..
.
//}}}

i was thinking the being based on an interface there'll be no problem calling those functions, but it does'nt seem to work...
should i be messing around with getDefinition() ? am i loading in the wrong application domain ?



On Wed, Oct 7, 2009 at 3:50 PM, Kastellanos Nikos <[hidden email]> wrote:
OK, I just found that I had to load it in a new Application Domain.
Replace line : var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
with: var ldrContext:LoaderContext = new LoaderContext(false, new
ApplicationDomain());



---------------------------------------
I have the following simple app that I use as a preloader.
This worked perfectly fine until recently when compiled with the parameter
'-main Preloader',
but with 2.04  I get this error:

TypeError: Error #1009: Cannot access a property or method of a null object
reference.
       at Preloader$/main()[J:\development\AIA
Microsite\Preloader\src/Preloader.hx:31]
       at MethodInfo-68()[<null>:1]
       at flash::Boot()[C:\Program
Files\Motion-Twin\haxe/std/flash9/Boot.hx:86]

This is also the case with 2.03. When I moved back to 2.02 it worked.
I guess something changed with the boot loader but I don't know the exact
details.
How can I load an SWF from inside another one?
 It looks like the Preloader::main() gets called initially,
 it starts loading the second SWF (for a few seconds I can see the custom
progress bar) and
 when the second SWF get's loaded, the Preloader::main() get's called again
for a second time!
That's when cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters throws
the #1009 error.





The source:
/**
* ...
* @author Kastellanos Nikos
*/
package ;

import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.Lib;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;




class Preloader
{
       var myLoader:Loader;
       var bar:MovieClip;
       var preloadBar:PreloadBar;

       static function main()
       {
               var src:String = "test.swf";
               var params:Dynamic<String> =
cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters; //Line 31
               src = (params.src==null)?src:params.src;
               var preloader:Preloader = new Preloader(src);
       }

       public function new(filename)
       {
               myLoader = new Loader();
               var myRequest:URLRequest = new URLRequest(filename);

               var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
               myLoader.load(myRequest,ldrContext);


myLoader.contentLoaderInfo.addEventListener(Event.OPEN,onOpen);

myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgres
s);
               myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
onComplete);
               Lib.current.addChild(myLoader);
               myLoader.visible = false;
               return;
       }

       function onOpen(evt:Event):Void
       {
               preloadBar = new PreloadBar();
               Lib.current.addChild(preloadBar);
               preloadBar.x = (Lib.current.stage.stageWidth -
preloadBar.width)/2;
               preloadBar.y = (Lib.current.stage.stageHeight -
preloadBar.height) / 2;
       }

       function onProgress(evt:ProgressEvent):Void
       {
               var ptc:Float = evt.bytesLoaded / evt.bytesTotal;

               if (evt.bytesLoaded == evt.bytesTotal)
               {
                       flash.Lib.current.removeChild(preloadBar);
               }
               preloadBar.iBar.scaleX = ptc;
       }

       function onComplete(evt:Event):Void
       {
               var loader:Loader = evt.target.loader;
       var info:LoaderInfo = loader.contentLoaderInfo;
               myLoader.visible = true;
       }
}


--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: RE: How to load another SWF in 2.03-2.04 ?

gershon
10x justin,
i take it that being Dynamic the loaded MovieClips will have infinite dynamic fields,and  this really seem to beat the purpose the plugin API...

Using reflection should protected it a bit no? if(Reflect.hasField(plugin, "run") && Reflect.isFunction(Reflect.field(plugin "run"))

i dont think i got that whole getDefinition() thing yet....
so i tried a "hack",
replacing:
               
var plug = new EditorPlugin();

with something like:
               // p is an array in the form [WhiteSpacePlugin.swf, FoldingPlugin.swf .... ]
                var className = p.split(".").shift();
                var plug : IEditorPlugin = Type.createInstance(Type.resolveClass(className), ["plugins/"+p]);

appreciate, gershon


On Thu, Oct 8, 2009 at 8:10 AM, Justin Lawerance Mills <[hidden email]> wrote:
ps you will need this

addChild(loader.content);

before 

var app: ApplicationDomain = _loader.contentLoaderInfo.applicationDomain;
var whiteSpacePlugin: MovieClip = cast( app.getDefinition("WhiteSpacePlugin")._this, MovieClip );

you prob don't need to extend movieclip... but if your loading a swf its a sprite/movieclip really anyway and being dynamic movieclip allows you to call what you like on it without compiler checking, but I am guessing you were trying to avoid that with the interface...  seems optimistic, separate application destroy type safety by the nature of being separate. 

 Cheers

;j

On 8 Oct 2009, at 07:01, Justin Lawerance Mills wrote:

As you prob realize from our irc chats I was loading haXe into flash preloader separate domain and loading flash graphics into haXe same domain hence the passing on of loaded data.

On 8 Oct 2009, at 06:54, Justin Lawerance Mills wrote:

OOPs typo...

var whiteSpacePlugin: MovieClip = cast( app.getDefinition("SiteMain")._this, MovieClip );

should be

var whiteSpacePlugin: MovieClip = cast( app.getDefinition("WhiteSpacePlugin")._this, MovieClip );


On 8 Oct 2009, at 06:50, Justin Lawerance Mills wrote:

Gershon

I have been loading haXe into flash movie but I changed below to cast so should be ok may need some tweaking

class EditorPlugin extends MovieClip{ ... }
...
public static var _this: WhiteSpacePlugin;
static function main(){ _this = new WhiteSpacePlugin(); }
public function new(){ super(); }
...
var app: ApplicationDomain = _loader.contentLoaderInfo.applicationDomain;
var whiteSpacePlugin: MovieClip = cast( app.getDefinition("SiteMain")._this, MovieClip );

//To setup listeners say if your passing on loader data of some external loaded assets

var externalEventInstance:Dynamic = whiteSpacePlugin.getSimpleLoadEventInstance();
var simpleLoadEvent: Class = app.getDefinition(getQualifiedClassName( externalEventInstance )) as Class;
whiteSpacePlugin.addEventListener( simpleLoadEvent.PROGRESS,    externalProgress   );
     whiteSpacePlugin.addEventListener( simpleLoadEvent.COMPLETED,   externalFinish      );

whiteSpacePlugin.start();


Left a few gaps and it may not be idea solution, but I fairly sure interfaces will not help in flash or haxe.  ( Ps if your using stageWidth in the loaded movie make sure you wait till its resolved )

Cheers

;j


On 8 Oct 2009, at 04:37, gershon wrote:

i'm doing something similar and have a question...
Got a class, called XmlEditor, in which i load swfs into a new application domain (new LoaderContext(false, new ApplicationDomain()))
Those swf are compiled from classes which extend the base EditorPlugin class, which conforms to an interface, IEditorPlugin.

here's some code for that:

//{{{ IEditorPlugin
interface IEditorPlugin {
    public var url : String;

    public function start() : Void;
    public function run() : Void;
    public function redraw() : Void;
}
//}}}


//{{{ EditorPlugin
class EditorPlugin implements IEditorPlugin {
    public var url : String;

    public var editor : XmlEditor;
    public var console : Console;

    public function new(?url:String=null) {
        if(url==null)
        url = Type.getClassName(Type.getClass(this)) + ".swf";
    }

    public function toString() : String {
        return "["+Type.getClassName(Type.getClass(this))+"]"+url;
    }

    public function start()  {}
    public function run()    {}
    public function redraw() {}

}
//}}}

so a plugin looks something like:

//{{{ WhiteSpacePlugin
/**
* Visualizes whitespace
*/
class WhiteSpacePlugin extends EditorPlugin {

    public static function main() {
    }

    public override function start() {
        console.log("Starting WhiteSpace Plugin...");
    }
.....
..
.
//}}}

i was thinking the being based on an interface there'll be no problem calling those functions, but it does'nt seem to work...
should i be messing around with getDefinition() ? am i loading in the wrong application domain ?



On Wed, Oct 7, 2009 at 3:50 PM, Kastellanos Nikos <[hidden email]> wrote:
OK, I just found that I had to load it in a new Application Domain.
Replace line : var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
with: var ldrContext:LoaderContext = new LoaderContext(false, new
ApplicationDomain());



---------------------------------------
I have the following simple app that I use as a preloader.
This worked perfectly fine until recently when compiled with the parameter
'-main Preloader',
but with 2.04  I get this error:

TypeError: Error #1009: Cannot access a property or method of a null object
reference.
       at Preloader$/main()[J:\development\AIA
Microsite\Preloader\src/Preloader.hx:31]
       at MethodInfo-68()[<null>:1]
       at flash::Boot()[C:\Program
Files\Motion-Twin\haxe/std/flash9/Boot.hx:86]

This is also the case with 2.03. When I moved back to 2.02 it worked.
I guess something changed with the boot loader but I don't know the exact
details.
How can I load an SWF from inside another one?
 It looks like the Preloader::main() gets called initially,
 it starts loading the second SWF (for a few seconds I can see the custom
progress bar) and
 when the second SWF get's loaded, the Preloader::main() get's called again
for a second time!
That's when cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters throws
the #1009 error.





The source:
/**
* ...
* @author Kastellanos Nikos
*/
package ;

import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.Lib;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;




class Preloader
{
       var myLoader:Loader;
       var bar:MovieClip;
       var preloadBar:PreloadBar;

       static function main()
       {
               var src:String = "test.swf";
               var params:Dynamic<String> =
cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters; //Line 31
               src = (params.src==null)?src:params.src;
               var preloader:Preloader = new Preloader(src);
       }

       public function new(filename)
       {
               myLoader = new Loader();
               var myRequest:URLRequest = new URLRequest(filename);

               var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
               myLoader.load(myRequest,ldrContext);


myLoader.contentLoaderInfo.addEventListener(Event.OPEN,onOpen);

myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgres
s);
               myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
onComplete);
               Lib.current.addChild(myLoader);
               myLoader.visible = false;
               return;
       }

       function onOpen(evt:Event):Void
       {
               preloadBar = new PreloadBar();
               Lib.current.addChild(preloadBar);
               preloadBar.x = (Lib.current.stage.stageWidth -
preloadBar.width)/2;
               preloadBar.y = (Lib.current.stage.stageHeight -
preloadBar.height) / 2;
       }

       function onProgress(evt:ProgressEvent):Void
       {
               var ptc:Float = evt.bytesLoaded / evt.bytesTotal;

               if (evt.bytesLoaded == evt.bytesTotal)
               {
                       flash.Lib.current.removeChild(preloadBar);
               }
               preloadBar.iBar.scaleX = ptc;
       }

       function onComplete(evt:Event):Void
       {
               var loader:Loader = evt.target.loader;
       var info:LoaderInfo = loader.contentLoaderInfo;
               myLoader.visible = true;
       }
}


--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: RE: How to load another SWF in 2.03-2.04 ?

jlm@justinfront.net
Reflection is not so helpful on dynamic, you may need to cast it as a typeDef or similar?  I tend to Try catch.

getDefinition is used on an applicationDomain to get classes by class string name (I rarely put my main classes in a package so its normally just the actual class name rather than a dot path ie 'net.justinfront.SiteMain' ).

I think one way or another you need to get info of classes from their applicationDomain, as I don't think class info of separate domains will be accessible via Type, its like it lives in a separate box and you can only access it via loader.content reference once loaded and via its ApplicationDomain instance.

One other approach you could try mainly as a conceptual experiment is create a SWC from your plugin and then compile in flex sdk then you can load into the same application domain, but remember for typing to work your loader will need atleast type information ( not sure interfaces are enough ) so really there is not a lot of file size saving from loading at run time... you might as well have xml that defines which classes to plugin and compile the classes in.


On 8 Oct 2009, at 13:18, gershon wrote:

10x justin,
i take it that being Dynamic the loaded MovieClips will have infinite dynamic fields,and  this really seem to beat the purpose the plugin API...

Using reflection should protected it a bit no? if(Reflect.hasField(plugin, "run") && Reflect.isFunction(Reflect.field(plugin "run"))

i dont think i got that whole getDefinition() thing yet....
so i tried a "hack",
replacing:
               
var plug = new EditorPlugin();

with something like:
               // p is an array in the form [WhiteSpacePlugin.swf, FoldingPlugin.swf .... ]
                var className = p.split(".").shift();
                var plug : IEditorPlugin = Type.createInstance(Type.resolveClass(className), ["plugins/"+p]);

appreciate, gershon


On Thu, Oct 8, 2009 at 8:10 AM, Justin Lawerance Mills <[hidden email]> wrote:
ps you will need this

addChild(loader.content);

before 

var app: ApplicationDomain = _loader.contentLoaderInfo.applicationDomain;
var whiteSpacePlugin: MovieClip = cast( app.getDefinition("WhiteSpacePlugin")._this, MovieClip );

you prob don't need to extend movieclip... but if your loading a swf its a sprite/movieclip really anyway and being dynamic movieclip allows you to call what you like on it without compiler checking, but I am guessing you were trying to avoid that with the interface...  seems optimistic, separate application destroy type safety by the nature of being separate. 

 Cheers

;j

On 8 Oct 2009, at 07:01, Justin Lawerance Mills wrote:

As you prob realize from our irc chats I was loading haXe into flash preloader separate domain and loading flash graphics into haXe same domain hence the passing on of loaded data.

On 8 Oct 2009, at 06:54, Justin Lawerance Mills wrote:

OOPs typo...

var whiteSpacePlugin: MovieClip = cast( app.getDefinition("SiteMain")._this, MovieClip );

should be

var whiteSpacePlugin: MovieClip = cast( app.getDefinition("WhiteSpacePlugin")._this, MovieClip );


On 8 Oct 2009, at 06:50, Justin Lawerance Mills wrote:

Gershon

I have been loading haXe into flash movie but I changed below to cast so should be ok may need some tweaking

class EditorPlugin extends MovieClip{ ... }
...
public static var _this: WhiteSpacePlugin;
static function main(){ _this = new WhiteSpacePlugin(); }
public function new(){ super(); }
...
var app: ApplicationDomain = _loader.contentLoaderInfo.applicationDomain;
var whiteSpacePlugin: MovieClip = cast( app.getDefinition("SiteMain")._this, MovieClip );

//To setup listeners say if your passing on loader data of some external loaded assets

var externalEventInstance:Dynamic = whiteSpacePlugin.getSimpleLoadEventInstance();
var simpleLoadEvent: Class = app.getDefinition(getQualifiedClassName( externalEventInstance )) as Class;
whiteSpacePlugin.addEventListener( simpleLoadEvent.PROGRESS,    externalProgress   );
     whiteSpacePlugin.addEventListener( simpleLoadEvent.COMPLETED,   externalFinish      );

whiteSpacePlugin.start();


Left a few gaps and it may not be idea solution, but I fairly sure interfaces will not help in flash or haxe.  ( Ps if your using stageWidth in the loaded movie make sure you wait till its resolved )

Cheers

;j


On 8 Oct 2009, at 04:37, gershon wrote:

i'm doing something similar and have a question...
Got a class, called XmlEditor, in which i load swfs into a new application domain (new LoaderContext(false, new ApplicationDomain()))
Those swf are compiled from classes which extend the base EditorPlugin class, which conforms to an interface, IEditorPlugin.

here's some code for that:

//{{{ IEditorPlugin
interface IEditorPlugin {
    public var url : String;

    public function start() : Void;
    public function run() : Void;
    public function redraw() : Void;
}
//}}}


//{{{ EditorPlugin
class EditorPlugin implements IEditorPlugin {
    public var url : String;

    public var editor : XmlEditor;
    public var console : Console;

    public function new(?url:String=null) {
        if(url==null)
        url = Type.getClassName(Type.getClass(this)) + ".swf";
    }

    public function toString() : String {
        return "["+Type.getClassName(Type.getClass(this))+"]"+url;
    }

    public function start()  {}
    public function run()    {}
    public function redraw() {}

}
//}}}

so a plugin looks something like:

//{{{ WhiteSpacePlugin
/**
* Visualizes whitespace
*/
class WhiteSpacePlugin extends EditorPlugin {

    public static function main() {
    }

    public override function start() {
        console.log("Starting WhiteSpace Plugin...");
    }
.....
..
.
//}}}

i was thinking the being based on an interface there'll be no problem calling those functions, but it does'nt seem to work...
should i be messing around with getDefinition() ? am i loading in the wrong application domain ?



On Wed, Oct 7, 2009 at 3:50 PM, Kastellanos Nikos <[hidden email]> wrote:
OK, I just found that I had to load it in a new Application Domain.
Replace line : var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
with: var ldrContext:LoaderContext = new LoaderContext(false, new
ApplicationDomain());



---------------------------------------
I have the following simple app that I use as a preloader.
This worked perfectly fine until recently when compiled with the parameter
'-main Preloader',
but with 2.04  I get this error:

TypeError: Error #1009: Cannot access a property or method of a null object
reference.
       at Preloader$/main()[J:\development\AIA
Microsite\Preloader\src/Preloader.hx:31]
       at MethodInfo-68()[<null>:1]
       at flash::Boot()[C:\Program
Files\Motion-Twin\haxe/std/flash9/Boot.hx:86]

This is also the case with 2.03. When I moved back to 2.02 it worked.
I guess something changed with the boot loader but I don't know the exact
details.
How can I load an SWF from inside another one?
 It looks like the Preloader::main() gets called initially,
 it starts loading the second SWF (for a few seconds I can see the custom
progress bar) and
 when the second SWF get's loaded, the Preloader::main() get's called again
for a second time!
That's when cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters throws
the #1009 error.





The source:
/**
* ...
* @author Kastellanos Nikos
*/
package ;

import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.Lib;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;




class Preloader
{
       var myLoader:Loader;
       var bar:MovieClip;
       var preloadBar:PreloadBar;

       static function main()
       {
               var src:String = "test.swf";
               var params:Dynamic<String> =
cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters; //Line 31
               src = (params.src==null)?src:params.src;
               var preloader:Preloader = new Preloader(src);
       }

       public function new(filename)
       {
               myLoader = new Loader();
               var myRequest:URLRequest = new URLRequest(filename);

               var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
               myLoader.load(myRequest,ldrContext);


myLoader.contentLoaderInfo.addEventListener(Event.OPEN,onOpen);

myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgres
s);
               myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
onComplete);
               Lib.current.addChild(myLoader);
               myLoader.visible = false;
               return;
       }

       function onOpen(evt:Event):Void
       {
               preloadBar = new PreloadBar();
               Lib.current.addChild(preloadBar);
               preloadBar.x = (Lib.current.stage.stageWidth -
preloadBar.width)/2;
               preloadBar.y = (Lib.current.stage.stageHeight -
preloadBar.height) / 2;
       }

       function onProgress(evt:ProgressEvent):Void
       {
               var ptc:Float = evt.bytesLoaded / evt.bytesTotal;

               if (evt.bytesLoaded == evt.bytesTotal)
               {
                       flash.Lib.current.removeChild(preloadBar);
               }
               preloadBar.iBar.scaleX = ptc;
       }

       function onComplete(evt:Event):Void
       {
               var loader:Loader = evt.target.loader;
       var info:LoaderInfo = loader.contentLoaderInfo;
               myLoader.visible = true;
       }
}


--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: RE: How to load another SWF in 2.03-2.04 ?

jlm@justinfront.net
Using the proxy class you can try bypassing application domains!... create a namespace with a Proxy class in your loader then in loaded you create another Proxy and can dump instances on it, I think you can then use the Proxy class in both movies to access instances as they are created provided you feed them to your Proxy.

I think it works but I must admit I am only going from some flash experiments of over a year ago and its really naughty and player may get fixed so not a reliable approach.



On 8 Oct 2009, at 14:16, Justin Lawerance Mills wrote:

Reflection is not so helpful on dynamic, you may need to cast it as a typeDef or similar?  I tend to Try catch.

getDefinition is used on an applicationDomain to get classes by class string name (I rarely put my main classes in a package so its normally just the actual class name rather than a dot path ie 'net.justinfront.SiteMain' ).

I think one way or another you need to get info of classes from their applicationDomain, as I don't think class info of separate domains will be accessible via Type, its like it lives in a separate box and you can only access it via loader.content reference once loaded and via its ApplicationDomain instance.

One other approach you could try mainly as a conceptual experiment is create a SWC from your plugin and then compile in flex sdk then you can load into the same application domain, but remember for typing to work your loader will need atleast type information ( not sure interfaces are enough ) so really there is not a lot of file size saving from loading at run time... you might as well have xml that defines which classes to plugin and compile the classes in.


On 8 Oct 2009, at 13:18, gershon wrote:

10x justin,
i take it that being Dynamic the loaded MovieClips will have infinite dynamic fields,and  this really seem to beat the purpose the plugin API...

Using reflection should protected it a bit no? if(Reflect.hasField(plugin, "run") && Reflect.isFunction(Reflect.field(plugin "run"))

i dont think i got that whole getDefinition() thing yet....
so i tried a "hack",
replacing:
               
var plug = new EditorPlugin();

with something like:
               // p is an array in the form [WhiteSpacePlugin.swf, FoldingPlugin.swf .... ]
                var className = p.split(".").shift();
                var plug : IEditorPlugin = Type.createInstance(Type.resolveClass(className), ["plugins/"+p]);

appreciate, gershon


On Thu, Oct 8, 2009 at 8:10 AM, Justin Lawerance Mills <[hidden email]> wrote:
ps you will need this

addChild(loader.content);

before 

var app: ApplicationDomain = _loader.contentLoaderInfo.applicationDomain;
var whiteSpacePlugin: MovieClip = cast( app.getDefinition("WhiteSpacePlugin")._this, MovieClip );

you prob don't need to extend movieclip... but if your loading a swf its a sprite/movieclip really anyway and being dynamic movieclip allows you to call what you like on it without compiler checking, but I am guessing you were trying to avoid that with the interface...  seems optimistic, separate application destroy type safety by the nature of being separate. 

 Cheers

;j

On 8 Oct 2009, at 07:01, Justin Lawerance Mills wrote:

As you prob realize from our irc chats I was loading haXe into flash preloader separate domain and loading flash graphics into haXe same domain hence the passing on of loaded data.

On 8 Oct 2009, at 06:54, Justin Lawerance Mills wrote:

OOPs typo...

var whiteSpacePlugin: MovieClip = cast( app.getDefinition("SiteMain")._this, MovieClip );

should be

var whiteSpacePlugin: MovieClip = cast( app.getDefinition("WhiteSpacePlugin")._this, MovieClip );


On 8 Oct 2009, at 06:50, Justin Lawerance Mills wrote:

Gershon

I have been loading haXe into flash movie but I changed below to cast so should be ok may need some tweaking

class EditorPlugin extends MovieClip{ ... }
...
public static var _this: WhiteSpacePlugin;
static function main(){ _this = new WhiteSpacePlugin(); }
public function new(){ super(); }
...
var app: ApplicationDomain = _loader.contentLoaderInfo.applicationDomain;
var whiteSpacePlugin: MovieClip = cast( app.getDefinition("SiteMain")._this, MovieClip );

//To setup listeners say if your passing on loader data of some external loaded assets

var externalEventInstance:Dynamic = whiteSpacePlugin.getSimpleLoadEventInstance();
var simpleLoadEvent: Class = app.getDefinition(getQualifiedClassName( externalEventInstance )) as Class;
whiteSpacePlugin.addEventListener( simpleLoadEvent.PROGRESS,    externalProgress   );
     whiteSpacePlugin.addEventListener( simpleLoadEvent.COMPLETED,   externalFinish      );

whiteSpacePlugin.start();


Left a few gaps and it may not be idea solution, but I fairly sure interfaces will not help in flash or haxe.  ( Ps if your using stageWidth in the loaded movie make sure you wait till its resolved )

Cheers

;j


On 8 Oct 2009, at 04:37, gershon wrote:

i'm doing something similar and have a question...
Got a class, called XmlEditor, in which i load swfs into a new application domain (new LoaderContext(false, new ApplicationDomain()))
Those swf are compiled from classes which extend the base EditorPlugin class, which conforms to an interface, IEditorPlugin.

here's some code for that:

//{{{ IEditorPlugin
interface IEditorPlugin {
    public var url : String;

    public function start() : Void;
    public function run() : Void;
    public function redraw() : Void;
}
//}}}


//{{{ EditorPlugin
class EditorPlugin implements IEditorPlugin {
    public var url : String;

    public var editor : XmlEditor;
    public var console : Console;

    public function new(?url:String=null) {
        if(url==null)
        url = Type.getClassName(Type.getClass(this)) + ".swf";
    }

    public function toString() : String {
        return "["+Type.getClassName(Type.getClass(this))+"]"+url;
    }

    public function start()  {}
    public function run()    {}
    public function redraw() {}

}
//}}}

so a plugin looks something like:

//{{{ WhiteSpacePlugin
/**
* Visualizes whitespace
*/
class WhiteSpacePlugin extends EditorPlugin {

    public static function main() {
    }

    public override function start() {
        console.log("Starting WhiteSpace Plugin...");
    }
.....
..
.
//}}}

i was thinking the being based on an interface there'll be no problem calling those functions, but it does'nt seem to work...
should i be messing around with getDefinition() ? am i loading in the wrong application domain ?



On Wed, Oct 7, 2009 at 3:50 PM, Kastellanos Nikos <[hidden email]> wrote:
OK, I just found that I had to load it in a new Application Domain.
Replace line : var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
with: var ldrContext:LoaderContext = new LoaderContext(false, new
ApplicationDomain());



---------------------------------------
I have the following simple app that I use as a preloader.
This worked perfectly fine until recently when compiled with the parameter
'-main Preloader',
but with 2.04  I get this error:

TypeError: Error #1009: Cannot access a property or method of a null object
reference.
       at Preloader$/main()[J:\development\AIA
Microsite\Preloader\src/Preloader.hx:31]
       at MethodInfo-68()[<null>:1]
       at flash::Boot()[C:\Program
Files\Motion-Twin\haxe/std/flash9/Boot.hx:86]

This is also the case with 2.03. When I moved back to 2.02 it worked.
I guess something changed with the boot loader but I don't know the exact
details.
How can I load an SWF from inside another one?
 It looks like the Preloader::main() gets called initially,
 it starts loading the second SWF (for a few seconds I can see the custom
progress bar) and
 when the second SWF get's loaded, the Preloader::main() get's called again
for a second time!
That's when cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters throws
the #1009 error.





The source:
/**
* ...
* @author Kastellanos Nikos
*/
package ;

import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.Lib;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;




class Preloader
{
       var myLoader:Loader;
       var bar:MovieClip;
       var preloadBar:PreloadBar;

       static function main()
       {
               var src:String = "test.swf";
               var params:Dynamic<String> =
cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters; //Line 31
               src = (params.src==null)?src:params.src;
               var preloader:Preloader = new Preloader(src);
       }

       public function new(filename)
       {
               myLoader = new Loader();
               var myRequest:URLRequest = new URLRequest(filename);

               var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
               myLoader.load(myRequest,ldrContext);


myLoader.contentLoaderInfo.addEventListener(Event.OPEN,onOpen);

myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgres
s);
               myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
onComplete);
               Lib.current.addChild(myLoader);
               myLoader.visible = false;
               return;
       }

       function onOpen(evt:Event):Void
       {
               preloadBar = new PreloadBar();
               Lib.current.addChild(preloadBar);
               preloadBar.x = (Lib.current.stage.stageWidth -
preloadBar.width)/2;
               preloadBar.y = (Lib.current.stage.stageHeight -
preloadBar.height) / 2;
       }

       function onProgress(evt:ProgressEvent):Void
       {
               var ptc:Float = evt.bytesLoaded / evt.bytesTotal;

               if (evt.bytesLoaded == evt.bytesTotal)
               {
                       flash.Lib.current.removeChild(preloadBar);
               }
               preloadBar.iBar.scaleX = ptc;
       }

       function onComplete(evt:Event):Void
       {
               var loader:Loader = evt.target.loader;
       var info:LoaderInfo = loader.contentLoaderInfo;
               myLoader.visible = true;
       }
}


--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: RE: How to load another SWF in 2.03-2.04 ?

jlm@justinfront.net
some of "my" flash experiments

And not trying to do this, it was more a case of struggling to use proxy as a resolve for model on loaded xml so you can ask for what you know is in the xml at the end view stage so you can easily add features to a view and xml without most of your movie caring.

On 8 Oct 2009, at 14:23, Justin Lawerance Mills wrote:

Using the proxy class you can try bypassing application domains!... create a namespace with a Proxy class in your loader then in loaded you create another Proxy and can dump instances on it, I think you can then use the Proxy class in both movies to access instances as they are created provided you feed them to your Proxy.

I think it works but I must admit I am only going from some flash experiments of over a year ago and its really naughty and player may get fixed so not a reliable approach.



On 8 Oct 2009, at 14:16, Justin Lawerance Mills wrote:

Reflection is not so helpful on dynamic, you may need to cast it as a typeDef or similar?  I tend to Try catch.

getDefinition is used on an applicationDomain to get classes by class string name (I rarely put my main classes in a package so its normally just the actual class name rather than a dot path ie 'net.justinfront.SiteMain' ).

I think one way or another you need to get info of classes from their applicationDomain, as I don't think class info of separate domains will be accessible via Type, its like it lives in a separate box and you can only access it via loader.content reference once loaded and via its ApplicationDomain instance.

One other approach you could try mainly as a conceptual experiment is create a SWC from your plugin and then compile in flex sdk then you can load into the same application domain, but remember for typing to work your loader will need atleast type information ( not sure interfaces are enough ) so really there is not a lot of file size saving from loading at run time... you might as well have xml that defines which classes to plugin and compile the classes in.


On 8 Oct 2009, at 13:18, gershon wrote:

10x justin,
i take it that being Dynamic the loaded MovieClips will have infinite dynamic fields,and  this really seem to beat the purpose the plugin API...

Using reflection should protected it a bit no? if(Reflect.hasField(plugin, "run") && Reflect.isFunction(Reflect.field(plugin "run"))

i dont think i got that whole getDefinition() thing yet....
so i tried a "hack",
replacing:
               
var plug = new EditorPlugin();

with something like:
               // p is an array in the form [WhiteSpacePlugin.swf, FoldingPlugin.swf .... ]
                var className = p.split(".").shift();
                var plug : IEditorPlugin = Type.createInstance(Type.resolveClass(className), ["plugins/"+p]);

appreciate, gershon


On Thu, Oct 8, 2009 at 8:10 AM, Justin Lawerance Mills <[hidden email]> wrote:
ps you will need this

addChild(loader.content);

before 

var app: ApplicationDomain = _loader.contentLoaderInfo.applicationDomain;
var whiteSpacePlugin: MovieClip = cast( app.getDefinition("WhiteSpacePlugin")._this, MovieClip );

you prob don't need to extend movieclip... but if your loading a swf its a sprite/movieclip really anyway and being dynamic movieclip allows you to call what you like on it without compiler checking, but I am guessing you were trying to avoid that with the interface...  seems optimistic, separate application destroy type safety by the nature of being separate. 

 Cheers

;j

On 8 Oct 2009, at 07:01, Justin Lawerance Mills wrote:

As you prob realize from our irc chats I was loading haXe into flash preloader separate domain and loading flash graphics into haXe same domain hence the passing on of loaded data.

On 8 Oct 2009, at 06:54, Justin Lawerance Mills wrote:

OOPs typo...

var whiteSpacePlugin: MovieClip = cast( app.getDefinition("SiteMain")._this, MovieClip );

should be

var whiteSpacePlugin: MovieClip = cast( app.getDefinition("WhiteSpacePlugin")._this, MovieClip );


On 8 Oct 2009, at 06:50, Justin Lawerance Mills wrote:

Gershon

I have been loading haXe into flash movie but I changed below to cast so should be ok may need some tweaking

class EditorPlugin extends MovieClip{ ... }
...
public static var _this: WhiteSpacePlugin;
static function main(){ _this = new WhiteSpacePlugin(); }
public function new(){ super(); }
...
var app: ApplicationDomain = _loader.contentLoaderInfo.applicationDomain;
var whiteSpacePlugin: MovieClip = cast( app.getDefinition("SiteMain")._this, MovieClip );

//To setup listeners say if your passing on loader data of some external loaded assets

var externalEventInstance:Dynamic = whiteSpacePlugin.getSimpleLoadEventInstance();
var simpleLoadEvent: Class = app.getDefinition(getQualifiedClassName( externalEventInstance )) as Class;
whiteSpacePlugin.addEventListener( simpleLoadEvent.PROGRESS,    externalProgress   );
     whiteSpacePlugin.addEventListener( simpleLoadEvent.COMPLETED,   externalFinish      );

whiteSpacePlugin.start();


Left a few gaps and it may not be idea solution, but I fairly sure interfaces will not help in flash or haxe.  ( Ps if your using stageWidth in the loaded movie make sure you wait till its resolved )

Cheers

;j


On 8 Oct 2009, at 04:37, gershon wrote:

i'm doing something similar and have a question...
Got a class, called XmlEditor, in which i load swfs into a new application domain (new LoaderContext(false, new ApplicationDomain()))
Those swf are compiled from classes which extend the base EditorPlugin class, which conforms to an interface, IEditorPlugin.

here's some code for that:

//{{{ IEditorPlugin
interface IEditorPlugin {
    public var url : String;

    public function start() : Void;
    public function run() : Void;
    public function redraw() : Void;
}
//}}}


//{{{ EditorPlugin
class EditorPlugin implements IEditorPlugin {
    public var url : String;

    public var editor : XmlEditor;
    public var console : Console;

    public function new(?url:String=null) {
        if(url==null)
        url = Type.getClassName(Type.getClass(this)) + ".swf";
    }

    public function toString() : String {
        return "["+Type.getClassName(Type.getClass(this))+"]"+url;
    }

    public function start()  {}
    public function run()    {}
    public function redraw() {}

}
//}}}

so a plugin looks something like:

//{{{ WhiteSpacePlugin
/**
* Visualizes whitespace
*/
class WhiteSpacePlugin extends EditorPlugin {

    public static function main() {
    }

    public override function start() {
        console.log("Starting WhiteSpace Plugin...");
    }
.....
..
.
//}}}

i was thinking the being based on an interface there'll be no problem calling those functions, but it does'nt seem to work...
should i be messing around with getDefinition() ? am i loading in the wrong application domain ?



On Wed, Oct 7, 2009 at 3:50 PM, Kastellanos Nikos <[hidden email]> wrote:
OK, I just found that I had to load it in a new Application Domain.
Replace line : var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
with: var ldrContext:LoaderContext = new LoaderContext(false, new
ApplicationDomain());



---------------------------------------
I have the following simple app that I use as a preloader.
This worked perfectly fine until recently when compiled with the parameter
'-main Preloader',
but with 2.04  I get this error:

TypeError: Error #1009: Cannot access a property or method of a null object
reference.
       at Preloader$/main()[J:\development\AIA
Microsite\Preloader\src/Preloader.hx:31]
       at MethodInfo-68()[<null>:1]
       at flash::Boot()[C:\Program
Files\Motion-Twin\haxe/std/flash9/Boot.hx:86]

This is also the case with 2.03. When I moved back to 2.02 it worked.
I guess something changed with the boot loader but I don't know the exact
details.
How can I load an SWF from inside another one?
 It looks like the Preloader::main() gets called initially,
 it starts loading the second SWF (for a few seconds I can see the custom
progress bar) and
 when the second SWF get's loaded, the Preloader::main() get's called again
for a second time!
That's when cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters throws
the #1009 error.





The source:
/**
* ...
* @author Kastellanos Nikos
*/
package ;

import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.Lib;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;




class Preloader
{
       var myLoader:Loader;
       var bar:MovieClip;
       var preloadBar:PreloadBar;

       static function main()
       {
               var src:String = "test.swf";
               var params:Dynamic<String> =
cast(Lib.current.stage.loaderInfo,LoaderInfo).parameters; //Line 31
               src = (params.src==null)?src:params.src;
               var preloader:Preloader = new Preloader(src);
       }

       public function new(filename)
       {
               myLoader = new Loader();
               var myRequest:URLRequest = new URLRequest(filename);

               var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
               myLoader.load(myRequest,ldrContext);


myLoader.contentLoaderInfo.addEventListener(Event.OPEN,onOpen);

myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgres
s);
               myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
onComplete);
               Lib.current.addChild(myLoader);
               myLoader.visible = false;
               return;
       }

       function onOpen(evt:Event):Void
       {
               preloadBar = new PreloadBar();
               Lib.current.addChild(preloadBar);
               preloadBar.x = (Lib.current.stage.stageWidth -
preloadBar.width)/2;
               preloadBar.y = (Lib.current.stage.stageHeight -
preloadBar.height) / 2;
       }

       function onProgress(evt:ProgressEvent):Void
       {
               var ptc:Float = evt.bytesLoaded / evt.bytesTotal;

               if (evt.bytesLoaded == evt.bytesTotal)
               {
                       flash.Lib.current.removeChild(preloadBar);
               }
               preloadBar.iBar.scaleX = ptc;
       }

       function onComplete(evt:Event):Void
       {
               var loader:Loader = evt.target.loader;
       var info:LoaderInfo = loader.contentLoaderInfo;
               myLoader.visible = true;
       }
}


--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Vectorial pictures

Kastellanos Nikos
In reply to this post by Lee Sylvester
One solution is to trace the png (Bitmap/trace) into an object.
This approach will increase the SWF size though.


There is a AS3 class called InteractivePNG that makes PNGs behave as a movie
object.
For example, the transparent pixels of the image wont trigger Mouse_Over.
(Unfortunately, Mouse_Out still works in the old way)
 There's no HaXe port I know off, so you have to port it yourself, or
compile it in
a SWF and import it in your project.


>Hi all,
>I'm making a map, and for the moment, my map is subdivised in
>departments. Anyway, there is a problem: i made my library with swfmill,
>and i use PNG. There is transparency, so, the picture is in a movieclip
>which is squared. I tried to import SVG with swfmill but it fails.
>
>I wanted to know if anyone had a solution about that. Can we manipulate
>SVG in haxe?




--
haXe - an open source web programming language
http://haxe.org
12