package com.yumei.layout
{
import com.greensock.events.LoaderEvent;
import com.greensock.loading.ImageLoader;
import com.greensock.loading.LoaderMax;
import com.greensock.loading.MP3Loader;
import com.greensock.loading.SWFLoader;
import com.yumei.config.Config;
import com.yumei.data.Mission;
import com.yumei.event.ActionEvent;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.system.Security;
import flash.system.SecurityDomain;
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;
import flash.utils.setTimeout;
import org.aswing.ASColor;
import org.aswing.ASFont;
import org.aswing.EmptyLayout;
import org.aswing.JLabel;
import org.aswing.JPanel;
import org.aswing.JProgressBar;
import org.aswing.JWindow;
import org.aswing.LayoutManager;
import org.aswing.util.HashMap;
public class LoadPanel extends JPanel
{
private var total:JLabel;
private var startpanel:StartPanel;//开始界面
private var preimages:HashMap=new HashMap();
private var urlloader:Loader;
private var resloader:Loader;
private var testUrlLoader:URLLoader;
public function LoadPanel()
{
setLayout(new EmptyLayout());
setName("loadPanel");
setSizeWH(Config.SWF_WIDTH,Config.SWF_HEIGHT);
setLocationXY(0,0);
Security.allowDomain("*");
Security.allowInsecureDomain("*");
flash.system.Security.loadPolicyFile("http://192.168.1.40:8080/crossdomain.xml");
urlloader=new Loader();
urlloader.load(new URLRequest("res/load.swf"));
urlloader.contentLoaderInfo.addEventListener(Event.COMPLETE,over);
resloader=new Loader();
resloader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,queueProgressHandler)
resloader.contentLoaderInfo.addEventListener(Event.COMPLETE,imageCompleteHandler)
// http://192.168.1.40:8080/MyDDing/fx/
// var loadercontext:LoaderContext=new LoaderContext(true,ApplicationDomain.currentDomain);
// resloader.load(new URLRequest("http://192.168.1.40:8080/.../fx/zxyj5.swf"),loadercontext);
testUrlLoader=new URLLoader();
testUrlLoader.dataFormat=URLLoaderDataFormat.BINARY;
testUrlLoader.addEventListener(Event.COMPLETE,testurlloaderok);
testUrlLoader.load(new URLRequest("http://192.168.1.40:8080/..../fx/zxyj5.swf"));
total=new JLabel();
total.setSizeWH(500,30);
total.setForeground(ASColor.BLACK);
total.setLocationXY(200,450);
this.append(total);
this.setChildIndex(total,numChildren-1);
//this.setChildIndex(total,numChildren-1);
}
public function testurlloaderok(ev:Event):void{
var loader:Loader=new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,test2);
loader.loadBytes(testUrlLoader.data,new LoaderContext(false,ApplicationDomain.currentDomain));
}
public function test2(ev:Event):void{
var mv:MovieClip=ev.target.content as MovieClip;
trace(getQualifiedClassName(mv.getChildByName("sp7")));
}
public function over(ev:Event):void{
var dis:DisplayObject=ev.target.content;
this.addChild(dis);
urlloader.contentLoaderInfo.removeEventListener(Event.COMPLETE,over);
}
private function queueProgressHandler(event:ProgressEvent):void
{
var fo:ASFont=new ASFont("宋体",24);
total.setFont(fo);
total.setText(""+Math.round((event.bytesLoaded/event.bytesTotal)*100) + "%");
//total.setText(""+event.target.progress);
if(event.bytesLoaded==event.bytesTotal)
{
resloader.removeEventListener(ProgressEvent.PROGRESS,queueProgressHandler);
}
}
private function imageCompleteHandler(ev:Event):void
{
// var myev:ActionEvent=new ActionEvent(ActionEvent.LOAD_COMPLETE);
// myev.panel=new StartPanel();
// ActionEvent.YUMEIEvent.dispatchEvent(myev);
var mv:MovieClip=ev.target.content as MovieClip;
Mission.source=mv;
for(var i:Number=0;i<mv.numChildren-1;i++)
{
trace(mv.getChildAt(i)+"---"+mv.getChildIndex(mv.getChildAt(i))+"---"+mv.getChildAt(i).name);
}
// trace(mv.getChildByName("educationmodelbutton"));
var sp:Sprite=Mission.source.getChildByName("educationmodelbutton") as Sprite;
sp.x=200,sp.y=200,sp.width=100;sp.height=50;
this.addChild(sp);
// trace("----"+ApplicationDomain.currentDomain.getDefinition("educationmodelbutton"));
trace("----"+getDefinitionByName("main"));
}
}
}