|
-
Senior Member
Full Browser BackGround Image Class
Hello all friends, I am trying to adapt a noponies class in KoolMoves 7.0.3, it resize the background with a fade effect.
The class is:
PHP Code:
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.COMPLETE, loaded);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorHandler);
loader.contentLoaderInfo.addEventListener(ProgressEvent.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(IOErrorEvent.IO_ERROR, onIOErrorHandler);
loader.contentLoaderInfo.removeEventListener(ProgressEvent.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:
PHP Code:
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:
Code:
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.
-
Not sure if I translated the error correctly, but you may try changing:
addEventListener(FullBrowserBg.UNLOAD_BG, unloadAll);//
to
addEventListener(Event.UNLOAD_BG, unloadAll);//
and all references to this......
Eric
-
Senior Member
I don't answer for the translate, my answer is Why it does't work ?. I not traslate so that it does not lead to confusion.
-
up to my .as in code
**Sidenote**
Your link to your running version has a flash detection script expecting a 9+ version of Flashplayer yet still asks me to upgrade when I'm running version 10+ . Wanted to mention
**
As for the errors you are getting...they are being generated due to other things failing in the ancillary classes (not the document class) deeper down in the class stack. Anyone running AS3 classes or porting AS3 classes should use a Flash Debug Player version to help them narrow down class failure causes.
Using the third version of noponies package, I had numerous problems (mainly with the expected fl.transitions.Tween classes and event listener scripting as well as if/else conditions based on them in the ancillary classes). Koolmoves cannot use fl. classes which are specific to the Adobe Flash IDE. You will have to replace these with TweenMax equivalents for use with Koolmoves. There were other errors as well and this package needed a fair amount of reworking to run. I don't like to have to rework packages as a rule because our compiler is still undergoing advancement by Bob and what does not work now may work later in it's pristine state (although this one never will due to it's reliance on the fl.transitions.Tween class and will always need TweenMax or other third party Tween engine for use in Koolmoves). I also do not like to redistribute packages or classes which have restrictions on them by the developer (which this one has) so for now I'm going to post the rewritten classes in my forum until I better understand the redistribution/modification rules noponies has placed on it before creating a openly public ZIP file for download (I have enough problems without a license hound biting my a##).
http://www.km-codex.com/media/NpFullBrowserBg.html
Running in the link above. Just like in noponies running example version, this one uses two images...click the stage to swap background images.
BTW...Congrats on the new blog byweb! We're adding a link to you at the codex to return the favor of yours. This is exactly what this platform needs...more people talking about it and supporting it. The site looks great
Last edited by Chris_Seahorn; 03-24-2009 at 12:19 AM.
-
up to my .as in code
The package modifications are posted in the "AS3 Ported Classes, Resources and Snippets" section of the codex forum. Copy, paste and run
Last edited by Chris_Seahorn; 03-24-2009 at 02:20 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|