package { import flash.events.Event; import flash.display.MovieClip; import flash.display.Loader; import flash.media.Sound; import flash.net.URLRequest; public class PeelMovie extends MovieClip { private const FLAGDESIGNSIZE:uint = 100; private const PEELDESIGNSIZE:uint = 500; // PEEL PARAMETERS // style of peel private var peelStyle:String; // sizes private var flagWidth:uint; private var flagHeight:uint; private var peelWidth:uint; private var peelHeight:uint; // peel position on page. Values: topleft || topright || bottomleft || bottomright private var peelPosition:String; // ad image on open peel private var bigURL: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. Values: 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 opened private var openSoundURL:String; // sound to play when peel is closed private var closeSoundURL:String; // link enabled. Values: true || false private var linkEnabled:Boolean; // where to open ad link, same or new window. Values: _self || _blank private var linkTarget:String; // ad link private var link:String; // speed of peel movement. Values: 1-9 private var peelSpeed:uint; // milliseconds to automatic open the peel. private var automaticOpen:uint; // milliseconds to automatic close the peel. private var automaticClose:uint; // enable a close button on opened peel. Values: true || false private var close_button_enable:Boolean; // text on close button private var text_on_close_button:String; // red value of close button color private var close_redValue:uint; // green value of close button color private var close_greenValue:uint; // blue value of close button color private var close_blueValue:uint; // END PEEL PARAMETERS // test variables for media load private var big_loaded:Boolean = false; private var open_sound_loaded:Boolean = false; private var close_sound_loaded:Boolean = false; // loader for big image and mirror image private var big_ldr:Loader = new Loader(); // loader for open sound private var openSound:Sound = new Sound(); // loader for close sound private var closeSound:Sound = new Sound(); // the peel clip private var thepeel:MovieClip; // resize scales private var toScaleX:Number; private var toScaleY:Number; /* * PeelMovie Constructor */ public function PeelMovie () { loadParams(); toScaleX = peelWidth/PEELDESIGNSIZE; toScaleY = peelHeight/PEELDESIGNSIZE; preload(); } /* * Load Peel Movie Parameters */ private function loadParams () { peelStyle = this.loaderInfo.parameters.peelStyle || "style1"; peelPosition = this.loaderInfo.parameters.peelPosition || "topright"; bigURL = this.loaderInfo.parameters.bigURL || "big.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; openSoundURL = this.loaderInfo.parameters.openSoundURL || ""; closeSoundURL = this.loaderInfo.parameters.closeSoundURL || ""; linkEnabled = Boolean(uint(this.loaderInfo.parameters.linkEnabled)) || false; linkTarget = this.loaderInfo.parameters.linkTarget || "_blank"; link = this.loaderInfo.parameters.link || "http://www.drupal.org"; peelSpeed = this.loaderInfo.parameters.peelSpeed || 4; automaticOpen = this.loaderInfo.parameters.automaticOpen || 0; automaticClose = this.loaderInfo.parameters.automaticClose || 0; close_button_enable = Boolean(uint(this.loaderInfo.parameters.close_button_enable)) || false; text_on_close_button = this.loaderInfo.parameters.text_on_close_button || "close"; close_redValue = this.loaderInfo.parameters.close_redValue || 0; close_greenValue = this.loaderInfo.parameters.close_greenValue || 0; close_blueValue = this.loaderInfo.parameters.close_blueValue || 0; flagWidth = this.loaderInfo.parameters.flagWidth || FLAGDESIGNSIZE; flagHeight = this.loaderInfo.parameters.flagHeight || FLAGDESIGNSIZE; peelWidth = this.loaderInfo.parameters.peelWidth || PEELDESIGNSIZE; peelHeight = this.loaderInfo.parameters.peelHeight || PEELDESIGNSIZE; } /* * start the Movie */ private function startMovie () { if (peelStyle == "style1") { thepeel = new Style1Peel(peelPosition, mirror, peelColor, peelColorStyle, redValue, greenValue, blueValue, linkEnabled, linkTarget, link, peelSpeed, automaticOpen, automaticClose, close_button_enable, text_on_close_button, close_redValue, close_greenValue, close_blueValue, big_ldr, openSound, closeSound, toScaleX, toScaleY, flagWidth, flagHeight, peelWidth, peelHeight); } else if (peelStyle == "style2") { thepeel = new Style2Peel(peelPosition, mirror, peelColor, peelColorStyle, redValue, greenValue, blueValue, linkEnabled, linkTarget, link, peelSpeed, automaticOpen, automaticClose, close_button_enable, text_on_close_button, close_redValue, close_greenValue, close_blueValue, big_ldr, openSound, closeSound, toScaleX, toScaleY, flagWidth, flagHeight, peelWidth, peelHeight); } else if (peelStyle == "style3") { thepeel = new Style3Peel(peelPosition, mirror, peelColor, peelColorStyle, redValue, greenValue, blueValue, linkEnabled, linkTarget, link, peelSpeed, automaticOpen, automaticClose, close_button_enable, text_on_close_button, close_redValue, close_greenValue, close_blueValue, big_ldr, openSound, closeSound, toScaleX, toScaleY, flagWidth, flagHeight, peelWidth, peelHeight); } addChild(thepeel); scaleMovie(); } /* * Test if all media is loaded */ private function allLoaded () : Boolean { if (!big_loaded) { return false; } if (!open_sound_loaded) { if (openSoundURL != "") { return false; } } if (!close_sound_loaded) { if (closeSoundURL != "") { return false; } } return true; } /* * big image load event handler */ private function bigImageLoaded (e:Event) : void { big_loaded = true; if (allLoaded()) { startMovie(); } } /* * open sound load event handler */ private function openSoundLoaded (e:Event) : void { open_sound_loaded = true; if (allLoaded()) { startMovie(); } } /* * close sound load event handler */ private function closeSoundLoaded (e:Event) : void { close_sound_loaded = true; if (allLoaded()) { startMovie(); } } /* * Preload images & sounds */ private function preload () { big_ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, bigImageLoaded); big_ldr.load(new URLRequest(bigURL)); if (openSoundURL != "") { openSound.addEventListener(Event.COMPLETE, openSoundLoaded); openSound.load(new URLRequest(openSoundURL)); } else { openSound = null; } if (closeSoundURL != "") { closeSound.addEventListener(Event.COMPLETE, closeSoundLoaded); closeSound.load(new URLRequest(closeSoundURL)); } else { closeSound = null; } } /* * Scale Movie */ private function scaleMovie () { // helper variable for a minor adjustment on position var positionOffset:uint; // scale the peel if (peelPosition == "topleft" || peelPosition == "bottomleft") { thepeel.scaleX = -1 * toScaleX; } else { thepeel.scaleX = toScaleX; } if (peelPosition == "bottomleft" || peelPosition == "bottomright") { thepeel.scaleY = -1 * toScaleY; } else { thepeel.scaleY = toScaleY; } // position peel if (peelPosition == "bottomleft" || peelPosition == "bottomright") { thepeel.y = peelHeight + (PEELDESIGNSIZE-peelHeight)/2; } else { thepeel.y = (PEELDESIGNSIZE-peelHeight)/2; } if (peelWidth % 2 == 0) { positionOffset = 0; } else { positionOffset = 1; } if (peelPosition == "topleft" || peelPosition == "bottomleft") { thepeel.x = PEELDESIGNSIZE - ((PEELDESIGNSIZE-peelWidth)/2 + positionOffset); } else { thepeel.x = (PEELDESIGNSIZE-peelWidth)/2 + positionOffset; } } } }