package { import fl.transitions.*; import fl.transitions.easing.*; import flash.events.Event; import flash.display.MovieClip; import flash.display.Loader; import flash.media.Sound; import flash.net.URLRequest; public class FlagMovie extends MovieClip { private var tm:TransitionManager; // in transition for peel add. Values: Blinds, Fade, Fly, Iris, Photo, Rotate, Squeeze, Wipe, PixelDissolve, Zoom. private var inTransition:String; // load duration parameter private var transitionDuration:uint; // style of flag private var flagStyle:String; // flag width and height. Suggested values 10-200 private var flagWidth:uint; private var flagHeight:uint; // size of design flag private const FLAGDESIGNSIZE:uint = 100; // peel position on page. Values: topleft || topright || bottomleft || bottomright private var peelPosition:String; // ad image on close peel private var smallURL:String; // mirror the image on peel. Values: true || false private var mirror:Boolean; // color of peel. Values: golden || silver || custom private var peelColor:String; // color of peel style. Value: flat || gradient private var peelColorStyle:String; // red value of custom color. Values 0-255 private var redValue:uint; // green value of custom color. Values 0-255 private var greenValue:uint; // blue value of custom color. Values 0-255 private var blueValue:uint; // sound to play when peel is loaded private var loadSoundURL:String; // speed of flag movement. Values: 1-9 private var flagSpeed:uint; // test variables for media load private var small_loaded:Boolean = false; private var load_sound_loaded:Boolean = false; // loader for small image and mirror image private var small_ldr:Loader = new Loader(); // loader for load sound private var loadSound:Sound = new Sound(); private var theflag:MovieClip; // resize scales private var toScaleX:Number; private var toScaleY:Number; /* * FlagMovie Constructor */ public function FlagMovie () { loadParams(); toScaleX = flagWidth/FLAGDESIGNSIZE; toScaleY = flagHeight/FLAGDESIGNSIZE; preload(); } /* * Load Flag Movie Parameters */ private function loadParams () { inTransition = this.loaderInfo.parameters.inTransition || "Squeeze"; transitionDuration = this.loaderInfo.parameters.transitionDuration || 4; flagStyle = this.loaderInfo.parameters.flagStyle || "style1"; flagWidth = this.loaderInfo.parameters.flagWidth || FLAGDESIGNSIZE; flagHeight = this.loaderInfo.parameters.flagHeight || FLAGDESIGNSIZE; peelPosition = this.loaderInfo.parameters.peelPosition || "topright"; smallURL = this.loaderInfo.parameters.smallURL || "small.jpg"; mirror = Boolean(uint(this.loaderInfo.parameters.mirror)) || false; peelColor = this.loaderInfo.parameters.peelColor || "custom"; peelColorStyle = this.loaderInfo.parameters.peelColorStyle || "gradient"; redValue = this.loaderInfo.parameters.redValue || 0; greenValue = this.loaderInfo.parameters.greenValue || 0; blueValue = this.loaderInfo.parameters.blueValue || 0; loadSoundURL = this.loaderInfo.parameters.loadSoundURL || ""; flagSpeed = this.loaderInfo.parameters.flagSpeed || 4; } /* * start the Movie */ private function startMovie () { if (flagStyle == "style1") { theflag = new Style1Flag(peelPosition, mirror, peelColor, peelColorStyle, redValue, greenValue, blueValue, flagSpeed, small_ldr, toScaleX, toScaleY); } else if (flagStyle == "style2") { theflag = new Style2Flag(peelPosition, mirror, peelColor, peelColorStyle, redValue, greenValue, blueValue, flagSpeed, small_ldr, toScaleX, toScaleY); } else if (flagStyle == "style3") { theflag = new Style3Flag(peelPosition, mirror, peelColor, peelColorStyle, redValue, greenValue, blueValue, flagSpeed, small_ldr, toScaleX, toScaleY); } addChild(theflag); scaleMovie(); if (inTransition != "none") { doTransition(); } } /* * Test if all media is loaded */ private function allLoaded () : Boolean { if (!small_loaded) { return false; } if (!load_sound_loaded) { if (loadSoundURL != "") { return false; } } if (load_sound_loaded) { loadSound.play(); } return true; } /* * small image load event handler */ private function smallImageLoaded (e:Event) : void { small_loaded = true; if (allLoaded()) { startMovie(); } } /* * load sound load event handler */ private function loadSoundLoaded (e:Event) : void { load_sound_loaded = true; if (allLoaded()) { startMovie(); } } /* * Preload images & sounds */ private function preload() { small_ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, smallImageLoaded); small_ldr.load(new URLRequest(smallURL)); if (loadSoundURL != "") { loadSound.addEventListener(Event.COMPLETE, loadSoundLoaded); loadSound.load(new URLRequest(loadSoundURL)); } } /* * Scale Movie */ private function scaleMovie () { // helper variable for a minor adjustment on position var positionOffset:uint; // scale the flag if (peelPosition == "topleft" || peelPosition == "bottomleft") { theflag.scaleX = -1 * toScaleX; } else { theflag.scaleX = toScaleX; } if (peelPosition == "bottomleft" || peelPosition == "bottomright") { theflag.scaleY = -1 * toScaleY; } else { theflag.scaleY = toScaleY; } // position the flag if (peelPosition == "bottomleft" || peelPosition == "bottomright") { theflag.y = flagHeight + (FLAGDESIGNSIZE-flagHeight)/2; } else { theflag.y = (FLAGDESIGNSIZE-flagHeight)/2; } if (flagWidth % 2 == 0) { positionOffset = 0; } else { positionOffset = 1; } if (peelPosition == "topleft" || peelPosition == "bottomleft") { theflag.x = FLAGDESIGNSIZE - ((FLAGDESIGNSIZE-flagWidth)/2 + positionOffset); } else { theflag.x = (FLAGDESIGNSIZE-flagWidth)/2 + positionOffset; } } /* * in transition if it is enabled */ private function doTransition () { tm = new TransitionManager(theflag); switch (inTransition) { case "Blinds": tm.startTransition({type:Blinds, direction:Transition.IN, duration:transitionDuration, easing:Regular.easeIn, numStrips:15, dimension:0}); break; case "Fade": tm.startTransition({type:Fade, direction:Transition.IN, duration:transitionDuration, easing:Strong.easeOut}); break; case "Fly": var flyStartPoint:uint; if (peelPosition == "topright") { flyStartPoint = 3; } else { flyStartPoint = 1; } tm.startTransition({type:Fly, direction:Transition.IN, duration:transitionDuration, easing:Elastic.easeOut, startPoint:flyStartPoint}); break; case "Iris": tm.startTransition({type:Iris, direction:Transition.IN, duration:transitionDuration, easing:Elastic.easeOut, startPoint:7, shape:Iris.CIRCLE}); break; case "Photo": tm.startTransition({type:Photo, direction:Transition.IN, duration:transitionDuration, easing:Strong.easeOut}); break; case "Rotate": var rotationCCW:Boolean; if (peelPosition == "topright") { rotationCCW = true; } else { rotationCCW = false; } tm.startTransition({type:Rotate, direction:Transition.IN, duration:transitionDuration, easing:None.easeOut, ccw:rotationCCW, degrees:360}); break; case "Squeeze": tm.startTransition({type:Squeeze, direction:Transition.IN, duration:transitionDuration, easing:Elastic.easeOut, dimension:0}); break; case "Wipe": tm.startTransition({type:Wipe, direction:Transition.IN, duration:transitionDuration, easing:Elastic.easeOut, startPoint:3}); break; case "PixelDissolve": tm.startTransition({type:PixelDissolve, direction:Transition.IN, duration:transitionDuration, easing:Regular.easeIn, xSections:20, ySections:20}); break; case "Zoom": tm.startTransition({type:Zoom, direction:Transition.IN, duration:transitionDuration, easing:Elastic.easeOut}); break; default: } } } }