Yes this is easy in Flex 2.

And it's not just the assets that you can use. You can use anything in the loaded swf as if it was in the main movie.

Sammi


Marcelo de Moraes Serpa wrote:
Hmmm... it seems that AVM2 has solved the classic problem we had with Flash that forced us to use RSL to do this kind of thing? I mean, we couldn´t just load a swf and use it´s assets on the parent context and vice-versa... is it
possible with flex 2?

Marcelo.

On 8/21/06, Samúel Jónasson <[EMAIL PROTECTED]> wrote:

Solved it.

Actually I was complicating things when trying to use the samples in
other articles.  Do this if you are interested in checking:

- Create a skin.swf
- Create one symbol and export it as "Button_up"
- Publish to build the swf.
- Use the following to include the skin at runtime.

package {

    import flash.display.*;
    import flash.errors.*;
    import flash.events.*;
    import flash.system.*;
    import flash.net.*;


    public class SkinTest extends Sprite{

        private var theSkin:Loader;

        public function SkinTest(){
            loadSkin();
        }

        private function loadSkin():void{

            theSkin = new Loader();
            theSkin.contentLoaderInfo.addEventListener(Event.COMPLETE,
skinLoadedHandler);
            theSkin.load(new URLRequest("skin.swf"));

        }

        private function skinLoadedHandler(event:Event):void{

            // try to use symbol from skin.swf
            var asset:Sprite = getSkinAsset("Button_up");
            addChild(asset);

        }

        private function getSkinAsset(skinAsset:String){

            var assetClass:Class =
theSkin.contentLoaderInfo.applicationDomain.getDefinition(skinAsset) as
Class;
            var asset:Object = new assetClass();

            return asset;

        }

    }

}


I hope this helps someone.

Sammi


Samúel Jónasson wrote:
> His.
>
> thank you for your response.
>
> I had read this article as well but didn't find the solution to my
> problem.  It is really important for me not to have to compile my app
> when the skin changes - so they need to load at runtime.  So if I have
> two files:
>
> - assets.swf
> - app.swf
>
> ...the symbols in assets.swf have a "auto generated" classes.  So a
> "Star" symbol would have a "Star" class generated on export.
> Then app.swf loads the assets.swf at runtime of with some magic ( as
> explained in some of the articles ) has access to the classes in
> assets.swf and can instantiate them.
>
> So if i need a star:
>
> var myStar:Star = new Star();
> addChild(myStar);
>
> ...and I get the symbol created in assets.swf.
>
>
> Matthew Ganz wrote:
>> hi.
>>
>> i don't have the answer to your question but i did see this post on
>> keith peters' blog this morning that may help you out:
>>
>> http://www.bit-101.com/blog/?p=853
>> ----- Original Message ----- From: "Samúel Jónasson"
>> <[EMAIL PROTECTED]>
>> To: <flashcoders@chattyfig.figleaf.com>
>> Sent: Monday, August 21, 2006 10:31 AM
>> Subject: [Flashcoders] Using assets from external SWF
>>
>>
>>> Hi everyone,
>>>
>>> I am trying to find out how to use external SWF as a library of
>>> assets that I can instantiate in my as3 projects. I have gone
>>> through several articles that "almost" explain this.  One in
>>> particular is "Loading Flex Skins at Runtime" at
>>> http://blogs.adobe.com/kiwi/2006/07/
>>>
>>> Basically I want to have my assets (skins, icons etc) in this
>>> external swf (assets.swf ) that I create in Flash 9.  Then load that
>>> file with the Loader class at runtime in an as3 project and
>>> instantiate the "classes" of the assets to add them to the stage,
>>> once or more.
>>>
>>> Does anyone have a working sample of this?
>>>
>>>
>>> _______________________________________________
>>> Flashcoders@chattyfig.figleaf.com
>>> To change your subscription options or search the archive:
>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>
>>> Brought to you by Fig Leaf Software
>>> Premier Authorized Adobe Consulting and Training
>>> http://www.figleaf.com
>>> http://training.figleaf.com
>>
>> _______________________________________________
>> Flashcoders@chattyfig.figleaf.com
>> To change your subscription options or search the archive:
>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
>> Brought to you by Fig Leaf Software
>> Premier Authorized Adobe Consulting and Training
>> http://www.figleaf.com
>> http://training.figleaf.com
>>
>
> _______________________________________________
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to