PDA

View Full Version : Dynamically loading a movie clip


devboy
04-30-2007, 10:06 PM
Hi,

I want to create a swf with media (movie clips) henceforth "lodee" and then load it in runtime from another swf, henceforth "loader".

Now, I saw a couple of places talking about using the [embed] tag. But this means that the movie clip is IN the generated swf.

I'm using flex 2. Is there a way to use the loadee swf resources only at runtime?

Cheers

dr_zeus
04-30-2007, 10:52 PM
See mx.controls.SWFLoader (http://livedocs.adobe.com/flex/201/langref/mx/controls/SWFLoader.html) to load SWF files into a Flex application at runtime.

It can also be used for images like JPG, PNG, and GIF.

devboy
05-01-2007, 05:30 AM
Thx,

Yeah I saw it I while I was looking around but I was not sure I could use it. Here's why:

Where do these mx. packages come from? are they a part of the flash player or are they external and get linked into my swf?
If they are linked into the swf, does the whole packgage get linked in or just the objects I use (size concerns)?
If I'm using flex 2 to write a strictly AS3 application can I still use mx. objects or are there limitations?
In general the docs go to lengths to distinguish flash (or AS3) from flex. I get that flex has a declarative syntax used to generate GUI that AS3 hasn't got, but in the end, don't they both stand on top of a unified VM using the same byte code?

One last thing, I don't want to display the whole swf in my app, I want to create specific movies from its libraries and use only them. How do I 'find' them? How do I create an instance of something in AS3 without 'knowing' the class definition in the calling code? Alternatively how do I know the definition without linking said class into my swf?

Cheers

dr_zeus
05-01-2007, 05:04 PM
You generally only use the mx.* classes when you want to make a Flex application. If you're using Flex Builder, but you create an ActionScript project, you can use some of the data-centric classes (for web services and things), but UI components won't be compatible at all. These classes are not part of Flash Player. The Flex framework is built from ActionScript, and these classes will be linked into your SWF, but only if you use them.

If you're just working with an ActionScript project in Flex Builder or you're developing in Flash CS3, you'll want to use flash.display.Loader (http://livedocs.adobe.com/flex/2/langref/flash/display/Loader.html) to load images or external SWF files. SWFLoader, which I mentioned previously, is a more advanced version that follows the guidelines for UI components in Flex.

By the way, you keep mentioning that you're using "Flex 2". From your second post, I understand that you're using Flex Builder, but in your first post, when you saying "using Flex 2" I assumed you meant that you were using the Flex framework. To avoid confusion, remember that the IDE for Flex is Flex Builder, and that simply saying "Flex" may cause confusion because Flex is more than its IDE.

devboy
05-01-2007, 07:36 PM
Understood,

What I still don't get is how to access content from the swf after its loaded.
How do I instantiate symbols?

dr_zeus
05-01-2007, 08:37 PM
Symbols in the age of Flash CS3 are now actually classes, and yes, you can access them at runtime.

You can access classes from a loaded SWF using the getDefinition function from the ApplicationDomain (http://livedocs.adobe.com/flex/201/langref/flash/system/ApplicationDomain.html) class. One of the examples in the documentation for ApplicationDomain includes a ClassLoader class that might be useful to you.

Please note, symbols in SWFs made with Flash 8 or below are not accessible at runtime. These SWFs run in the old virtual machine and can only be displayed. If you need these symbols, you should either upgrade the FLA file to the new version and re-export the SWF or embed the symbols at compile time.

SmackMe
05-02-2007, 08:13 AM
Understood,

What I still don't get is how to access content from the swf after its loaded.
How do I instantiate symbols?

you might want to check these links:
https://admin.adobe.acrobat.com/_a300965365/p75214263/
http://www.digitalflipbook.com/archives/2007/03/associating_cus.php