ActionScript 3 as3全背景图像类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 as3全背景图像类相关的知识,希望对你有一定的参考价值。
package com.jasonhulbert.display{
import flash.events.Event;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.errors.IOError;
import flash.events.IOErrorEvent;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
public class FullBackground extends Sprite {
var ldr:Loader;
var ldrReq:URLRequest;
var bmp:Bitmap;
var minW:Number;
var minH:Number;
var stageW:Number;
var stageH:Number;
var scaler:Number;
public function FullBackground(_imageURL:String, _minW:Number, _minH:Number) {
minW = _minW;
minH = _minH;
ldr = new Loader ;
ldrReq = new URLRequest(_imageURL);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
addEventListener(Event.ADDED_TO_STAGE, onAdd);
}
private function onAdd(event:Event):void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, onStageResize);
ldr.load(ldrReq);
}
private function onLoaded(event:Event):void {
bmp = Bitmap(ldr.content);
bmp.smoothing = true;
addChild(bmp);
resizeImage();
}
private function onIOError(event:IOErrorEvent):void {
trace("Error loading background image: " + event);
}
private function resizeImage():void {
stageW = stage.stageWidth;
stageH = stage.stageHeight;
if (stageH / stageW > this.height / this.width) {
scaler = this.width / this.height;
this.width = stageH * scaler;
this.height = stageH;
} else {
scaler = this.height / this.width;
this.height = stageW * scaler;
this.width = stageW;
}
this.x = (stageW / 2) - (this.width / 2);
this.y = 0;
}
private function onStageResize(event:Event):void {
resizeImage();
}
}
}
以上是关于ActionScript 3 as3全背景图像类的主要内容,如果未能解决你的问题,请参考以下文章
ActionScript 3 AS3:图像加载
ActionScript 3 AS3获取图像的平均颜色
ActionScript 3 AS3:在图像上放置叠加层
ActionScript 3 AS3 - 来自URL的缓存图像
ActionScript 3 AS3图像映射,圆形,斜角滤波器
ActionScript 3 来自AS3的PHP图像上传器