FLA files
Monkey Targets Forums/Flash/FLA files
| ||
I notice that a lot of Flash sites request that you include their own start-up animations. These are generally .fla animation files. Has anyone tried incorporating something like this? Maybe by building it as a swf first, then building in FlashBuilder? |
| ||
Ok, I've managed to implement the intro animations into my pre-loader. First I had to build the FLA in CS4, making sure I added enough frames to the main layer (so that actual number of frames in Layer 1 matched the number of frame in the animations included within Layer 1 - I'm not really sure of the correct terminology here!) Then put a stop(); command in the very last keyframe on Layer 1 (otherwise the anim will loop and play sound even beyond the life of the preloader). Now publish the intro as a swf. Create a FlashBuilder project out of your MonkeyGame.as and data. Pop the swf in your src folder, allow with a background image if you wish. Create a new file in the project called Preloader.as and use this code: // My preloader package { import flash.display.*; import flash.events.*; import flash.text.*; import flash.utils.getDefinitionByName; [SWF(width = "640", height = "480")] public class Preloader extends MovieClip { [Embed(source = 'bg.png')] private const PICTURE:Class; // PUT YOUR BACKGROUND IMAGE HERE [Embed(source = 'intro_logo.swf')] private var MOVIE:Class; // CHANGE INTRO ANIM HERE privateprivate var myPicture:Bitmap = new PICTURE; private var myMovie:MovieClip = new MOVIE; private const allowedSite:String = "newstarsoccer.com"; // SITE LOCK HERE private var loader:Sprite = new Sprite(); private const loaderColor:uint = 0xffffff; private var loaded:Number = 0; private var introdone:Boolean = false; private var count:int; public function Preloader() { // loader information stage.addEventListener(Event.ENTER_FRAME, progress); myMovie.addEventListener(Event.ENTER_FRAME, handleFrame); addChild(myPicture); addChild(myMovie); // SET THE POSITION OF YOUR ANIMATION myMovie.scaleX = stage.stageWidth / myMovie.width; myMovie.scaleY = myMovie.scaleX; myMovie.x = 0 - (((myMovie.width * myMovie.scaleX) - stage.stageWidth) / 2); myMovie.y = 120; // show loader addChild(loader); loader.x = 0; loader.y = stage.stageHeight - 32; } private function progress(e:Event):void { // how much we've loaded thus far loaded = loaderInfo.bytesLoaded / loaderInfo.bytesTotal; // update loader graphic loader.graphics.clear(); loader.graphics.beginFill(loaderColor); loader.graphics.drawRect(0, 0, loaded * stage.stageWidth, 32); loader.graphics.endFill(); // done loading? if (loaderInfo.bytesLoaded >= loaderInfo.bytesTotal && introdone == true) { startup(); } } private function handleFrame(e:Event):void { count += 1; if (count >= 150) // CHANGE INTRO LENGTH (Num of frames in intro swf) { introdone = true; if (loaderInfo.bytesLoaded >= loaderInfo.bytesTotal) { startup(); } } } private function startup():void { // remove event listener(s) stage.removeEventListener(Event.ENTER_FRAME, progress); myMovie.removeEventListener(Event.ENTER_FRAME, handleFrame); // hide loader stop(); // remove all the children var i:int = numChildren; while (i --) { removeChildAt(i); } // site lock if (this.root.loaderInfo.url.indexOf(allowedSite) == -1) { return; } // go to the main class var mainClass:Class = getDefinitionByName("MonkeyGame") as Class; parent.addChild(new mainClass as DisplayObject); // remove self parent.removeChild(this) } } } Then in MonkeyGame.as add this line after [SWF(width="640",height="480")]: [Frame(factoryClass="Preloader")] Build in FlashBuilder and find your new swf in the bin folder. |