Lib.attach from runtime loaded swf

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

Lib.attach from runtime loaded swf

go2ghana
Hi,
is there a way to use the Lib.attach functionality - i.e. duplicate  
display objects
from an swf-lib loaded at runtime in a similar way as when compiled with
-swf-lib?

Cordially,
Axel


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

Re: Lib.attach from runtime loaded swf

Jan_Flanders


On Fri, Apr 15, 2011 at 6:40 PM, Axel Huizinga <[hidden email]> wrote:
Hi,
is there a way to use the Lib.attach functionality - i.e. duplicate  display objects
from an swf-lib loaded at runtime in a similar way as when compiled with -swf-lib?

Cordially,
Axel


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

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/ApplicationDomain.html#getDefinition%28%29
(check the examples)

http://haxe.org/api/flash9/system/applicationdomain

(that's also what Lib.attach does internally:)
http://code.google.com/p/haxe/source/browse/trunk/std/flash9/Lib.hx#72

Jan

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

Re: Lib.attach from runtime loaded swf

Baluta Cristian
I'm using this:

for (swf in swfs) if (swf.target.applicationDomain.hasDefinition ( className )) {
var def = swf.target.applicationDomain.getDefinition ( className );
var classInstance = Type.createInstance ( cast (def, Class<Dynamic>), args );
return classInstance;
}

swfs is an array of Event objects.

On Fri, Apr 15, 2011 at 8:13 PM, Jan Flanders <[hidden email]> wrote:


On Fri, Apr 15, 2011 at 6:40 PM, Axel Huizinga <[hidden email]> wrote:
Hi,
is there a way to use the Lib.attach functionality - i.e. duplicate  display objects
from an swf-lib loaded at runtime in a similar way as when compiled with -swf-lib?

Cordially,
Axel


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

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/ApplicationDomain.html#getDefinition%28%29
(check the examples)

http://haxe.org/api/flash9/system/applicationdomain

(that's also what Lib.attach does internally:)
http://code.google.com/p/haxe/source/browse/trunk/std/flash9/Lib.hx#72

Jan

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



--
Băluță Cristian
http://ralcr.com
http://imagin.ro

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

Re: Lib.attach from runtime loaded swf

Jan_Flanders
Here is a working example:

Main.hx:
class Main extends flash.display.MovieClip
{
    public function new()
    {
        super();
        var context = new flash.system.LoaderContext(false, flash.system.ApplicationDomain.currentDomain);
        var request = new flash.net.URLRequest("assets.swf");
        var loader = new flash.display.Loader();
        loader.contentLoaderInfo.addEventListener("complete", onLoadComplete);
        loader.load(request, context);
    }
    function onLoadComplete(event)
    {
        var ball = flash.Lib.attach("Ball");
        addChild(ball);
    }
    public static function main()
    {
        flash.Lib.current.addChild(new Main());
    }
}

Ball.hx:
class Ball extends flash.display.MovieClip
{
    public function new()
    {
        super();
        graphics.beginFill(0xFF0000);
        graphics.drawCircle(50, 50, 50);
        addEventListener("mouseDown" , onMouseDown);
        addEventListener("mouseUp" , onMouseUp);
    }
    private function onMouseDown(event)
    {
        startDrag();
    }
    private function onMouseUp(event)
    {
        stopDrag();
    }
}

build.hxml:
Main
-main Main
-swf index.swf
-swf-version 10

--next
Ball
-swf assets.swf
-swf-version 10




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

libattachloaded.zip (10K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Lib.attach from runtime loaded swf

Dion Whitehead Amago
The hydrax/Pushbutton engine has encapsulated this in a class that
requires very few dependencies.  You can load swfs via embedded bytes or
urls.
https://github.com/dionjwa/Hydrax

Usage:

var swf = new SwfResource("somename", Source.url("http://blah") or
Source.bytes(haxe.Resource.getBytes('swfid'));

function onLoad() {
    var yourMovieClip = Type.createInstance(swf.getClass("classname"), []);
}

swf.load(onLoad);


There's a proper demo in [hydrax root dir]/demos/resources

Dion

Jan Flanders wrote:

> Here is a working example:
>
> Main.hx:
> class Main extends flash.display.MovieClip
> {
>      public function new()
>      {
>          super();
>          var context = new flash.system.LoaderContext(false,
> flash.system.ApplicationDomain.currentDomain);
>          var request = new flash.net.URLRequest("assets.swf");
>          var loader = new flash.display.Loader();
>          loader.contentLoaderInfo.addEventListener("complete",
> onLoadComplete);
>          loader.load(request, context);
>      }
>      function onLoadComplete(event)
>      {
>          var ball = flash.Lib.attach("Ball");
>          addChild(ball);
>      }
>      public static function main()
>      {
>          flash.Lib.current.addChild(new Main());
>      }
> }
>
> Ball.hx:
> class Ball extends flash.display.MovieClip
> {
>      public function new()
>      {
>          super();
>          graphics.beginFill(0xFF0000);
>          graphics.drawCircle(50, 50, 50);
>          addEventListener("mouseDown" , onMouseDown);
>          addEventListener("mouseUp" , onMouseUp);
>      }
>      private function onMouseDown(event)
>      {
>          startDrag();
>      }
>      private function onMouseUp(event)
>      {
>          stopDrag();
>      }
> }
>
> build.hxml:
> Main
> -main Main
> -swf index.swf
> -swf-version 10
>
> --next
> Ball
> -swf assets.swf
> -swf-version 10
>
>
>

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

Re: Lib.attach from runtime loaded swf

go2ghana
Am 15.04.2011 20:54, schrieb dionjw:

> The hydrax/Pushbutton engine has encapsulated this in a class that
> requires very few dependencies.  You can load swfs via embedded bytes
> or urls.
> https://github.com/dionjwa/Hydrax
>
> Usage:
>
> var swf = new SwfResource("somename", Source.url("http://blah") or
> Source.bytes(haxe.Resource.getBytes('swfid'));
>
> function onLoad() {
>    var yourMovieClip = Type.createInstance(swf.getClass("classname"),
> []);
> }
>
> swf.load(onLoad);
>
>
> There's a proper demo in [hydrax root dir]/demos/resources
>
> Dion
>
> Jan Flanders wrote:
>> Here is a working example:
thanks to everybody - lot of useful options - this time you guys
reminded me that miracles are natural.
one only needs to ask to save a lot of work :)

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

Re: Lib.attach from runtime loaded swf

justin_mills
In reply to this post by go2ghana
Axel

If your not extending the MovieClip then it can be really useful to cast it as a MovieClip then you can for instance use an array of MovieClips.  So more or less similar to what others have said.  But for me it can be very useful to treat graphics elements as generic MovieClips in my code rather than specific class types.

    public static function getLibraryMovie( nom: String ):MovieClip
    {
        var c =  Type.resolveClass( nom );
                if ( c == null )
                {
                        trace( nom +' MovieClip not in the library ' );
                        return new MovieClip();
                }
        return cast( Type.createInstance( c, new Array() ), MovieClip);

    }


Cheers ;j


 On Fri 15/04/11 22:16, Axel Huizinga [hidden email] wrote:

> Am 15.04.2011 20:54, schrieb dionjw:
> > The hydrax/Pushbutton engine has encapsulated this
> in a class that
> requires very few dependencies.  You can load swfs
> via embedded bytes
> or urls.
> > https://github.com/dionjwa/Hydrax
>>
> > Usage:
> >
> > var swf = new SwfResource("somename", Source.url("http://blah") or
>
> Source.bytes(haxe.Resource.getBytes('swfid'));
>
> > function onLoad() {
> >    var yourMovieClip =
> Type.createInstance(swf.getClass("classname"),
> []);
> > }
> >
> > swf.load(onLoad);
> >
> >
> > There's a proper demo in [hydrax root
> dir]/demos/resources
>
> > Dion
> >
> > Jan Flanders wrote:
> >> Here is a working example:
> thanks to everybody - lot of useful options - this time you guys
> reminded me that miracles are natural.
> one only needs to ask to save a lot of work :)
>
> --
> haXe - an open source web programming language
> http://haxe.org
>
>


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