views:

2909

answers:

2

OK,

It sounds complicated, but it's not. Here goes: I want to use some assets ( buttons, etc. ) I'm creating in flash in a flex actionscript project. Since all my assets are bellow 10K, I'm not planning to load a swf ,wait until it's loaded and create the interface. I want to use a swc and just instance the clips I need. Also, I want my Button class to have some extra properties, and this is where the problem occurs.

If in the Linkage Properties in the Flash IDE I add a reference to a custom Button Class and trace a child of the Button MovieClip, I get the right trace. If then I create a Button, in the Main class in Flex, using the generated swc file and trace the same child of the Button MovieClip, I get null.

Why is that ? Is there anyway to get around this ? I've considered using the Flex Component Kit, but since I'm working on a simple actionscript project and I'm not using the Flex framework, I see no point in using the Component Kit at this point.

Thanks!

+2  A: 

I'm not sure if I'm reading your question correctly but are you essestially wanting to embed an image/asset that is available from the start, insted of the image/assets being loaded once the app initilises?

If this is the case then check out this link. It explains how to embed any asset into an actionscript project. http://kennethsutherland.com/2009/04/21/why-flex-why-actionscript-why-flash/

Hope this is what your after.

kenneth
yup. you got it. I want to have some assets embedded to avoid loading. Thanks for the post. It's handy one, but that scenario( making a flex as project 'compilable' in flash ) is slightly the opposite of mine ( compiling a swc in flash for use in flex ). Now I'm heaving second thoughts on compiling the swc in flash, and thinking about just using the [Embed] tag from a swf. Still, I thought that you could link a MovieClip to an external class, package that up in a swc and use it in flex. It's a problem I didn't imagine I would run into and I'm curious what's the solution.
George Profenza
I'd pressume (I'm not a flash CS3 person) its down to what is actually included inside the SWC that the flash IDE has generated. When I was creating my AS3 project for a flash project, one of our designers explained that they didn't use Embed (its not part of flash) but that they placed any assets onto the stage to make sure that they were there from the start, but they couldn't 'embed' them using script. So I'm pressumming that your SWC contains the code, but not the assets. Try decompiling the SWC (open using winzip to get swf) then use decomiler to open swf http://www.flash-decompiler.com/
kenneth
If the assets are not in the SWC then you'll need to use the method included in the blog post to Embed them.
kenneth
thanks for the help kenneth. I am a flash person, started as a designer, animator and picked up actionscript along the way. I use Flex Builder as well, but I mostly I work on actionscript projects without using the Flex framework. There's a lot of cool flex stuff to learn from your blog. Thanks for sharing.
George Profenza
A: 

I think I got it.

My Button MovieClip was linking to a class in the the same src folder as the rest of my actionscript code in the Flex actionscript project. (The as3 classpath was set to "../", from the assets folder where the .fla file lives, one level up to src )

When Flash compiled, the class was found and I got in the .swc file. That is why I got the symbol traced from flash. When Flex compiled, the class was found in the src directory, so a new version of the same class was compiled, although it already existed in the swc file. Since flex found the .as file, but wouldn't know I had it linked to a symbol in the Flash IDE ( I don't think it can do that ), Flex created its version of the class, but since no symbol was linked to that class, the child of Button I was tracing was null.

I guess using packages and keeping the fla linked classes separate so Flex wouldn't compile the same class twice.

The weird thing is I didn't get any warning or error, so I assumed everything was fine.

A quick and not so dirty workaround was to delete the physical Button class from the filesystem, so that Flash could generate it's version on compile time and have references to the children of the Button symbol. Then in Flex I cread a class that extends Button and added the code I needed. Since the generated class got compiled in the .swc file, Flex could see that and I had no problem extending.

That was it! Bob's you're uncle!

I assumes that what happens, I am not 100% sure. It's something my intuition takes for granted through observation, so I might be technically wrong. If anyone has any correction they're welcome.

George Profenza
George, is this THE solution? I still have trouble with writing the classes for my SWC MC's in Flex ... thanks :)
dani
@dani Once the SWC is compiled from Flash and added to Flex, can you instantiate classes from that SWC ? If so, all you need need to do is either use coposition or inheritance(whatever works for your setup best).
George Profenza
Thanks George - I do can instantiate the SWC classes and then composition / inheritance seems to be the keyword. Your hint helped me find this article:http://www.flashdevelop.org/wikidocs/index.php?title=AS3:FlexAndFlashCS3Workflow
dani