Jul
25
package Bearbox.Loading
{
import flash.display.Loader;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFormat;
import mx.events.FlexEvent;
import mx.preloaders.DownloadProgressBar;
public class MyLoading extends DownloadProgressBar
{
private var _preloader:Sprite;
private var logo:Loader = new Loader();
private var loadingBar:Shape = new Shape();
private var txt:TextField = new TextField();
public function MyLoading()
{
// logo
logo.load(new URLRequest("http://www.dv9.org/images/logo.gif"));
addChild(logo);
// loading bar
addChild(loadingBar);
// txt
var style:TextFormat = new TextFormat(null, null, 0xFFFFFF, null, null, null, null, null, "center");
txt.defaultTextFormat = style;
txt.selectable = false;
txt.width = 200;
txt.height = 50;
addChild(txt);
super();
}
override public function set preloader(value:Sprite):void
{
_preloader = value;
_preloader.contextMenu = MyContextMenu.getMyContextNenu();
//四个侦听~分别是加载进度 / 加载完毕 / 初始化进度 / 初始化完毕
_preloader.addEventListener(ProgressEvent.PROGRESS, loadProgressHandler);
_preloader.addEventListener(Event.COMPLETE, loadCompleteHandler);
_preloader.addEventListener(FlexEvent.INIT_PROGRESS, loadInitProgressHandler);
_preloader.addEventListener(FlexEvent.INIT_COMPLETE, loadInitCompleteHandler);
stage.addEventListener(Event.RESIZE, resizeHandler);
resizeHandler(null);
}
private function loadProgressHandler(event:ProgressEvent):void
{
var ratio:Number = event.bytesLoaded/event.bytesTotal;
// loading bar
loadingBar.graphics.clear();
loadingBar.graphics.beginFill(Math.random() * 0xFFFFFF);
loadingBar.graphics.drawRect(0,0, ratio*128, 5);
loadingBar.graphics.endFill();
// txt
txt.text = "Dv9.Org� 载中 " + ((ratio*100)>>0) + "%";
}
private function loadCompleteHandler(event:Event):void
{
txt.text = "Dv9.Org加载成功!";
}
private function loadInitProgressHandler(event:FlexEvent):void
{
txt.text = "Dv9.Org加载中!";
}
private function loadInitCompleteHandler(event:FlexEvent):void
{
txt.text = "Dv9.Org加载中成功!";
_preloader.removeEventListener(ProgressEvent.PROGRESS, loadProgressHandler);
_preloader.removeEventListener(Event.COMPLETE, loadCompleteHandler);
_preloader.removeEventListener(FlexEvent.INIT_PROGRESS, loadInitProgressHandler);
_preloader.removeEventListener(FlexEvent.INIT_COMPLETE, loadInitCompleteHandler);
stage.removeEventListener(Event.RESIZE, resizeHandler);
//最后这个地方需要dpepatch一个Event.COMPLETE事件..表示� 载完毕让swf继续操作~
dispatchEvent(new Event(Event.COMPLETE));
}
private function resizeHandler(event:Event):void
{
logo.x = (stage.stageWidth-128) * .5;
logo.y = (stage.stageHeight-185) *.5;
loadingBar.x = (stage.stageWidth-128) * .5;
loadingBar.y = (stage.stageHeight-185) *.5 + 128;
txt.x = (stage.stageWidth-200) * .5;
txt.y = (stage.stageHeight-185) *.5 + 135;
graphics.clear();
graphics.beginFill(0x333333);
graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
graphics.endFill();
}
}
}
{
import flash.display.Loader;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFormat;
import mx.events.FlexEvent;
import mx.preloaders.DownloadProgressBar;
public class MyLoading extends DownloadProgressBar
{
private var _preloader:Sprite;
private var logo:Loader = new Loader();
private var loadingBar:Shape = new Shape();
private var txt:TextField = new TextField();
public function MyLoading()
{
// logo
logo.load(new URLRequest("http://www.dv9.org/images/logo.gif"));
addChild(logo);
// loading bar
addChild(loadingBar);
// txt
var style:TextFormat = new TextFormat(null, null, 0xFFFFFF, null, null, null, null, null, "center");
txt.defaultTextFormat = style;
txt.selectable = false;
txt.width = 200;
txt.height = 50;
addChild(txt);
super();
}
override public function set preloader(value:Sprite):void
{
_preloader = value;
_preloader.contextMenu = MyContextMenu.getMyContextNenu();
//四个侦听~分别是加载进度 / 加载完毕 / 初始化进度 / 初始化完毕
_preloader.addEventListener(ProgressEvent.PROGRESS, loadProgressHandler);
_preloader.addEventListener(Event.COMPLETE, loadCompleteHandler);
_preloader.addEventListener(FlexEvent.INIT_PROGRESS, loadInitProgressHandler);
_preloader.addEventListener(FlexEvent.INIT_COMPLETE, loadInitCompleteHandler);
stage.addEventListener(Event.RESIZE, resizeHandler);
resizeHandler(null);
}
private function loadProgressHandler(event:ProgressEvent):void
{
var ratio:Number = event.bytesLoaded/event.bytesTotal;
// loading bar
loadingBar.graphics.clear();
loadingBar.graphics.beginFill(Math.random() * 0xFFFFFF);
loadingBar.graphics.drawRect(0,0, ratio*128, 5);
loadingBar.graphics.endFill();
// txt
txt.text = "Dv9.Org� 载中 " + ((ratio*100)>>0) + "%";
}
private function loadCompleteHandler(event:Event):void
{
txt.text = "Dv9.Org加载成功!";
}
private function loadInitProgressHandler(event:FlexEvent):void
{
txt.text = "Dv9.Org加载中!";
}
private function loadInitCompleteHandler(event:FlexEvent):void
{
txt.text = "Dv9.Org加载中成功!";
_preloader.removeEventListener(ProgressEvent.PROGRESS, loadProgressHandler);
_preloader.removeEventListener(Event.COMPLETE, loadCompleteHandler);
_preloader.removeEventListener(FlexEvent.INIT_PROGRESS, loadInitProgressHandler);
_preloader.removeEventListener(FlexEvent.INIT_COMPLETE, loadInitCompleteHandler);
stage.removeEventListener(Event.RESIZE, resizeHandler);
//最后这个地方需要dpepatch一个Event.COMPLETE事件..表示� 载完毕让swf继续操作~
dispatchEvent(new Event(Event.COMPLETE));
}
private function resizeHandler(event:Event):void
{
logo.x = (stage.stageWidth-128) * .5;
logo.y = (stage.stageHeight-185) *.5;
loadingBar.x = (stage.stageWidth-128) * .5;
loadingBar.y = (stage.stageHeight-185) *.5 + 128;
txt.x = (stage.stageWidth-200) * .5;
txt.y = (stage.stageHeight-185) *.5 + 135;
graphics.clear();
graphics.beginFill(0x333333);
graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
graphics.endFill();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
preloader="Bearbox.Loading" creationComplete="init()">
<mx:Script>
<![CDATA[
private function init():void
{
this.contextMenu = MyContextMenu.getMyContextNenu();
}
]]>
</mx:Script>
</mx:Application>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
preloader="Bearbox.Loading" creationComplete="init()">
<mx:Script>
<![CDATA[
private function init():void
{
this.contextMenu = MyContextMenu.getMyContextNenu();
}
]]>
</mx:Script>
</mx:Application>



Flex制作一个emai
flex与flash的交
