As3.0常用类:Fullbackground(全屏背景)
2012-02-06 12:14:08 来源:本站整理核心提示:package { import flash.display.Sprite; import flash.display.Stage; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.
- package {
- import flash.display.Sprite;
- import flash.display.Stage;
- import flash.display.StageAlign;
- import flash.display.StageScaleMode;
- import flash.display.Bitmap;
- import flash.display.Loader;
- import flash.net.URLRequest;
- import flash.events.*;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- public class FullBackground {
- private var stage:Stage;
- private var _imageHolder:Sprite;
- private var _bitmap:Bitmap;
- private var _loader:Loader;
- private var _urlReqest:URLRequest;
- private var loadProgress_txt:TextField;
- private var percent:Number;
- function FullBackground(stageRef:Stage, url:String) {
- //设置舞台
- stage = stageRef;
- stage.scaleMode = StageScaleMode.NO_SCALE;
- stage.align = StageAlign.TOP_LEFT;
- stage.addEventListener(Event.RESIZE, stageResized);
- //载入图像
- _loader = new Loader();
- _urlReqest = new URLRequest(url);
- _loader.load(_urlReqest);
- _loader.contentLoaderInfo.addEventListener(Event.OPEN,showPreloader);
- _loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,showProgress);
- _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,showLoadResult);
- loadProgress_txt= new TextField();
- loadProgress_txt.autoSize=TextFieldAutoSize.LEFT;
- }
- private function showProgress(event:ProgressEvent):void {
- //preloader ready
- trace("progressHandler: bytesLoaded=" + event.bytesLoaded
+ " bytesTotal=" + event.bytesTotal);- percent = Math.round((event.bytesLoaded/event.bytesTotal)*100);
- loadProgress_txt.text = percent + "%";
- stage.addChild(loadProgress_txt);
- }
- private function showPreloader(event:Event):void {
- trace("show preloader");
- }
- //完成载入显示图像
- private function showLoadResult(event:Event):void {
- trace(_loader.contentLoaderInfo);
- var loader:Loader = Loader(event.target.loader);
- _bitmap = Bitmap(loader.content);
- _imageHolder = new Sprite();
- _bitmap.y -= _bitmap.height;
- _bitmap.smoothing = true;
- stage.addChild(_imageHolder);
- _imageHolder.addChild(_bitmap);
- //检查缩放并调整
- _imageHolder.width = stage.stageWidth;
- _imageHolder_imageHolder.scaleY = _imageHolder.scaleX;
- if (_imageHolder.height < stage.stageHeight) {
- _imageHolder.height = stage.stageHeight;
- _imageHolder_imageHolder.scaleX = _imageHolder.scaleY;
- }
- _imageHolder.y = stage.stageHeight;
- }
- //stageResized 事件
- private function stageResized(event:Event):void {
- _imageHolder.width = stage.stageWidth;
- _imageHolder_imageHolder.scaleY = _imageHolder.scaleX;
- if (_imageHolder.height < stage.stageHeight) {
- _imageHolder.height = stage.stageHeight;
- _imageHolder_imageHolder.scaleX = _imageHolder.scaleY;
- }
- _imageHolder.y = stage.stageHeight;
- }
- }
- }
将代码另存为FullBackground.as文件,此类需要两个参数,一个是舞台引用,另一个是url即背景图像的地址,打开flash cs3新建一个影片,在第一帧中输入代码:
import FullBackground;
var testfullbackground = new FullBackground(stage,"1280_800.jpg");
Tags:As 常用 Fullbackground
编辑录入:coldstar [复制链接] [打 印]- ››asp.net页面弄成伪静态页面
- ››常用的Windows 7操作系统实用技巧
- ››Asp.net 中将汉字转换成拼音的方法
- ››ASP.NET及JS中的cookie基本用法
- ››ASP.NET获取MS SQL Server安装实例
- ››asp.net实现调用百度pai 在线翻译英文转中文
- ››ASP.NET页面选项进行提示判断
- ››Asp.net定时执行程序
- ››ASP.NET中利用DataList实现图片无缝滚动
- ››ASP.NET验证控件RequiredFieldValidator
- ››ASP.NET中使用System.Net.Mail发邮件
- ››ASP.NET中获取用户控件中控件的ID
更多精彩
赞助商链接