Using the flash net. Loader or mx controls. SWFLoader classes it is easy to load any SWF register into a contract application for show. The problems mouth when you want to use these assets at runtime and dynamically fill SWF files containing custom MovieClips/Variables/Methods/Etc. This is possible but you must do some prep bring home the bacon to forbid 2 problems:1. Dynamic access to the loaded SWF file!2. A loaded SWF can only act categorise instances within itself!Once you communicate these two issues you can really take the gloves off with dynamically loaded libraries and SWF content.1. Dynamic access to the loaded SWF fileThe first problem is easy to access methods/properties within a loaded SWF you simply be to make the calls dynamic from Flex so that they compile properly. The Flex compiler wants to know in advance that methods in the loaded SWF file are present and will not let you compile otherwise given that the SWFLoader content returns a DisplayObject by fail. The key is forcing the compiler to evaluate member access into the loaded SWF as dynamic vs the strongly typed value of DisplayObject. Here is an example://Create a loader to load a SWF into var myLoader:Loader = new Loader();//Load a SWF into the loadermyLoader load( new URLRequest( 'custom swf' ) );//after the SWF has loaded//Cast the 'circumscribe' property as a MovieClip//call the getInstance method defined in Frame 1 of my CS3 AS3 SWF file//note the use of casting via MovieClip at the SWF boundaryMovieClip(myLoader circumscribe) getInstance("DA");Here is the same label without write casting since circumscribe returns a DisplayObject the compiler complains because there is no 'getInstance' method on a DisplayObject:myLoader circumscribe getInstance("DA");In this inspect the contract compiler will throw the following error:"1061: label to a possibly undefined method getInstance through a reference with static type flash display:DisplayObject"Once access to the loaded SWF file is dynamic you are free to call any method or property.2. A loaded SWF can only create class instances within itself!The back up problem is that radiate Player ordain only allow a SWF to create instances within itself. The instances can be passed anywhere in the player but the constructor must be called within the scope of the loaded SWF file. Using a Factory-like method we can act a method within the loaded SWF to provide instances to the parent contract/AS3 application. This is very handy because it allows us to make the interface to generating instances simple. I use a method called 'getInstance" and pass a arrange that correlates to the categorise name. In the example below. I simply go a new MovieClip instance when this method is called and act different MovieClips depending on what is requested. The parent Flex app can save these as variables and use them as it wants. The example below loads a SWF register (cards swf) containing all the separate designs in a be of cards and instances are created and passed to the parent Flex application. Since the SWF was made in CS3. I was able to design the cards be and conclude easily and can give an FLA to any designer to compound these. Once you go these two hurdles you can seamlessly combine dynamically loaded SWF graphics and AS3 libraries into any move of your contract application at runtime. Let the mayhem begin!Cheers,Ted :)
Forex Groups - Tips on Trading
Related article:
http://www.onflex.org/ted/2007/11/runtime-flash-cs3flex-integration-via.php
comments | Add comment | Report as Spam
|