byweb
03-20-2009, 07:31 AM
Hello all friends, I am trying to adapt a noponies (http://www.byweb.es/KM7Labs/FullBrowser/) class in KoolMoves 7.0.3, it resize the background with a fade effect.
The class is:
package noponies.display {
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import gs.TweenLite;//using TweenLite to handle alpha fades
import flash.events.*;
import flash.net.URLRequest;
import flash.display.Loader;
public class FullBrowserBg extends Sprite {
/************************************************** *****************************
VARIABLES
************************************************** *****************************/
private var useMinStageSize:Boolean;//use a minimum stage size?
private var XminStageSize:int;
private var YminStageSize:int;
public static const BG_LOADED:String = "newslideloaded";
public static const BG_LOADING:String = "newslideloading";
public static const UNLOAD_BG:String = "unloadbg";
private var imageUrl:String;//array of images
private var loader:Loader;//loader for loading in images
private var slide:Sprite;//sprite that serves as a content holder for loaders content
private var bitMapBg:Bitmap;
private var stageWidth:Number;
private var stageHeight: Number;
private var imageScaleProp:Number;
//constructor
public function FullBrowserBg(imageUrl:String, useMinStageSize:Boolean=false, XminStageSize:int = 400, YminStageSize:int = 400 ) {
this.imageUrl = imageUrl;
this.useMinStageSize = useMinStageSize
this.XminStageSize = XminStageSize
this.YminStageSize = YminStageSize
//Set up the listeners
addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);//use stage as listener for custom events
addEventListener(FullBrowserBg.UNLOAD_BG, unloadAll);//listener for unload all event
}
//load the image
private function loadBgImage() {
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, loaded);
loader.contentLoaderInfo.addEventListener(IOErrorE vent.IO_ERROR, onIOErrorHandler);
loader.contentLoaderInfo.addEventListener(Progress Event.PROGRESS, progressHandler);
var request:URLRequest = new URLRequest(String(imageUrl));//access our array of url's
loader.load(request);
}
private function loaded(event:Event):void {
//dispatch the loaded event
dispatchEvent(new Event(FullBrowserBg.BG_LOADED, true));
slide = new Sprite();//create a sprite to load bitmap into
slide.alpha = 0;//set the slide content to have an alpha of 0
slide.x = 0;
slide.y = 0;
bitMapBg = Bitmap(loader.content);//get the loaders content as a bitmap
bitMapBg.smoothing = true;//turn on smoothing
slide.addChild(bitMapBg);//add the bitmap to the slide sprite
addChild(slide);
//remove the eventListeners on the loader object and set it to null
loader.contentLoaderInfo.removeEventListener(Event .COMPLETE, loaded);
loader.contentLoaderInfo.removeEventListener(IOErr orEvent.IO_ERROR, onIOErrorHandler);
loader.contentLoaderInfo.removeEventListener(Progr essEvent.PROGRESS, progressHandler);
loader = null;
//set initial scale of image
resizeBg(slide);
//alpha in the content
TweenLite.to(slide, 5, {alpha:1});//alpha in the slides
}
//here we do the general resizing of our images, this function is called via the stages resize handler.
//First, check that we are not below the minimum size set for scaling, if we are, we don't scale
private function resizeBg(targetSprite:Sprite):void {
if (useMinStageSize) {
if (stage.stageWidth<XminStageSize || stage.stageHeight <YminStageSize) {
return;
}
}
//access stage width here. We want to respond to stage dimension changes immediately
stageWidth = stage.stageWidth;
stageHeight= stage.stageHeight;
if (stageHeight/stageWidth>targetSprite.height/targetSprite.width) {
imageScaleProp = targetSprite.width/targetSprite.height;
targetSprite.height = stageHeight;
targetSprite.width = stageHeight*imageScaleProp;
} else {
imageScaleProp = targetSprite.height/targetSprite.width;
targetSprite.width = stageWidth;
targetSprite.height = stageWidth*imageScaleProp;
}
targetSprite.x = 0;
targetSprite.y = 0;
}
//resize listener
private function resizeListener(event:Event):void {
resizeBg(slide);
}
//added to stage handler
private function addedToStageHandler(event:Event):void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeListener);
stageWidth = stage.stageWidth;
stageHeight= stage.stageHeight;
loadBgImage();
}
// IO Error handling
private function onIOErrorHandler(event:IOErrorEvent):void {
trace("There has been an ioErrorHandler: " + event);
}
//progress handler, uncomment and use, if desired.
private function progressHandler(event:ProgressEvent):void {
//trace("bytesLoaded = " + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
//dispatch the loading event
//dispatchEvent(new Event(FullBrowserBg.BG_LOADING, true));
}
//dispatch an unload event to remove all listeners and set content to null
private function unloadAll(event:Event):void {
stage.removeEventListener(Event.RESIZE, resizeListener);
stage.removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
slide.removeChildAt(0)
bitMapBg = null
removeChild(slide);
slide = null;
removeEventListener(FullBrowserBg.UNLOAD_BG, unloadAll);
}
}
}
and in the KM time line actions have:
import noponies.display.FullBrowserBg;
var newBrowserBg:FullBrowserBg = new FullBrowserBg("images/holdsteady.jpg", false);
addChildAt(newBrowserBg,0);
When I test it with (Ctrl+Alt+Enter) the error output show me:
ReferenceError: Error #1069: No se encontró la propiedad UNLOAD_BG en noponies.display.FullBrowserBg y no hay ningún valor predeterminado.
at noponies.display::FullBrowserBg()
at fullBrouser_fun::MainTimeline/frame1()
It is in Spanish, I sorry.
How can I to fix this ?. Thanks.
The class is:
package noponies.display {
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import gs.TweenLite;//using TweenLite to handle alpha fades
import flash.events.*;
import flash.net.URLRequest;
import flash.display.Loader;
public class FullBrowserBg extends Sprite {
/************************************************** *****************************
VARIABLES
************************************************** *****************************/
private var useMinStageSize:Boolean;//use a minimum stage size?
private var XminStageSize:int;
private var YminStageSize:int;
public static const BG_LOADED:String = "newslideloaded";
public static const BG_LOADING:String = "newslideloading";
public static const UNLOAD_BG:String = "unloadbg";
private var imageUrl:String;//array of images
private var loader:Loader;//loader for loading in images
private var slide:Sprite;//sprite that serves as a content holder for loaders content
private var bitMapBg:Bitmap;
private var stageWidth:Number;
private var stageHeight: Number;
private var imageScaleProp:Number;
//constructor
public function FullBrowserBg(imageUrl:String, useMinStageSize:Boolean=false, XminStageSize:int = 400, YminStageSize:int = 400 ) {
this.imageUrl = imageUrl;
this.useMinStageSize = useMinStageSize
this.XminStageSize = XminStageSize
this.YminStageSize = YminStageSize
//Set up the listeners
addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);//use stage as listener for custom events
addEventListener(FullBrowserBg.UNLOAD_BG, unloadAll);//listener for unload all event
}
//load the image
private function loadBgImage() {
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, loaded);
loader.contentLoaderInfo.addEventListener(IOErrorE vent.IO_ERROR, onIOErrorHandler);
loader.contentLoaderInfo.addEventListener(Progress Event.PROGRESS, progressHandler);
var request:URLRequest = new URLRequest(String(imageUrl));//access our array of url's
loader.load(request);
}
private function loaded(event:Event):void {
//dispatch the loaded event
dispatchEvent(new Event(FullBrowserBg.BG_LOADED, true));
slide = new Sprite();//create a sprite to load bitmap into
slide.alpha = 0;//set the slide content to have an alpha of 0
slide.x = 0;
slide.y = 0;
bitMapBg = Bitmap(loader.content);//get the loaders content as a bitmap
bitMapBg.smoothing = true;//turn on smoothing
slide.addChild(bitMapBg);//add the bitmap to the slide sprite
addChild(slide);
//remove the eventListeners on the loader object and set it to null
loader.contentLoaderInfo.removeEventListener(Event .COMPLETE, loaded);
loader.contentLoaderInfo.removeEventListener(IOErr orEvent.IO_ERROR, onIOErrorHandler);
loader.contentLoaderInfo.removeEventListener(Progr essEvent.PROGRESS, progressHandler);
loader = null;
//set initial scale of image
resizeBg(slide);
//alpha in the content
TweenLite.to(slide, 5, {alpha:1});//alpha in the slides
}
//here we do the general resizing of our images, this function is called via the stages resize handler.
//First, check that we are not below the minimum size set for scaling, if we are, we don't scale
private function resizeBg(targetSprite:Sprite):void {
if (useMinStageSize) {
if (stage.stageWidth<XminStageSize || stage.stageHeight <YminStageSize) {
return;
}
}
//access stage width here. We want to respond to stage dimension changes immediately
stageWidth = stage.stageWidth;
stageHeight= stage.stageHeight;
if (stageHeight/stageWidth>targetSprite.height/targetSprite.width) {
imageScaleProp = targetSprite.width/targetSprite.height;
targetSprite.height = stageHeight;
targetSprite.width = stageHeight*imageScaleProp;
} else {
imageScaleProp = targetSprite.height/targetSprite.width;
targetSprite.width = stageWidth;
targetSprite.height = stageWidth*imageScaleProp;
}
targetSprite.x = 0;
targetSprite.y = 0;
}
//resize listener
private function resizeListener(event:Event):void {
resizeBg(slide);
}
//added to stage handler
private function addedToStageHandler(event:Event):void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeListener);
stageWidth = stage.stageWidth;
stageHeight= stage.stageHeight;
loadBgImage();
}
// IO Error handling
private function onIOErrorHandler(event:IOErrorEvent):void {
trace("There has been an ioErrorHandler: " + event);
}
//progress handler, uncomment and use, if desired.
private function progressHandler(event:ProgressEvent):void {
//trace("bytesLoaded = " + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
//dispatch the loading event
//dispatchEvent(new Event(FullBrowserBg.BG_LOADING, true));
}
//dispatch an unload event to remove all listeners and set content to null
private function unloadAll(event:Event):void {
stage.removeEventListener(Event.RESIZE, resizeListener);
stage.removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
slide.removeChildAt(0)
bitMapBg = null
removeChild(slide);
slide = null;
removeEventListener(FullBrowserBg.UNLOAD_BG, unloadAll);
}
}
}
and in the KM time line actions have:
import noponies.display.FullBrowserBg;
var newBrowserBg:FullBrowserBg = new FullBrowserBg("images/holdsteady.jpg", false);
addChildAt(newBrowserBg,0);
When I test it with (Ctrl+Alt+Enter) the error output show me:
ReferenceError: Error #1069: No se encontró la propiedad UNLOAD_BG en noponies.display.FullBrowserBg y no hay ningún valor predeterminado.
at noponies.display::FullBrowserBg()
at fullBrouser_fun::MainTimeline/frame1()
It is in Spanish, I sorry.
How can I to fix this ?. Thanks.