开发者

Automating the creation of Flash/AS3 projects

My goal is to make a flash/as3 program that would pull multiple sets of data (images and texts) from the database and compile and save a flash video project for each one. What might be the best way to go about making this work? I checked but wasn't able to find a function that would publish the flash project in it's current state, so I don't think I can execute the entire process in a single flash/as3 file. My only other option is to have some other program/batch file take care of the querying the database and compiling multiple flash/as3 movie开发者_Go百科s by starting up a flash program and passing it the parameters of the data it needs to build 1 complete project for 1 set of data. Is there a program that can help me create .swf files automatically? Is it even possible to pass in init params to flash/as3 project? Any thoughts or ideas on this would be greatly appreciated :)!


I'm not sure if I've understood your question in entirety, but you could use the command line compiler mxmlc.exe from the Flex SDK to compile your flash project dynamically.

You may generate the code (with your application) for your flash application as .as file, where you can use embed statements for your images and string variables for your text. This generated main class should use code from other class to handle these "dynamic data". Then give that generated class to the compiler as start point for your flash application and you will get a .swf as result.

Edit

Here an example for a static class that handled the dynamic data.

package  
{
    import flash.display.Sprite;
    import flash.text.TextField;
    
    public class Base extends Sprite
    {
        
        public function Base() 
        {
        }
        
        public function init(dyn:Main) : void
        {
            // add a new instance of the embedded image
            addChild( new dyn.DynamicImage1() );
            // add a new text field with the dynmaic text
            var text:TextField = new TextField();
            text.text = dyn.DynmaicText1;
        }
        
    }

}

And here an example for the generated main class

package 
{
    import flash.display.Sprite;
    import flash.events.Event;
    
    public class Main extends Sprite 
    {
        
        [Embed(source = '../relative/path/to/dynamic/image.png')]
        public var DynamicImage1:Class;
        
        public var DynmaicText1:String = "This is directly from Database";
        
        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event = null):void 
        {
            var base:Base = addChild(new Base()) as Base;
            base.init(this);
        }
        
    }
    
}

Now give Main to the compiler as start point.

At all, this is only a simple example and could be far more generalized using arrays, Vector<T> and Interfaces and so on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜