package com
{
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
import flash.events.TextEvent;
import flash.events.TimerEvent;
import flash.net.URLLoader;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.utils.Timer;
import fl.transitions.*;
import fl.transitions.easing.*;
public class Main extends MovieClip
{
private static var pt:Main;
private var XML_FILE_PATH:String = "data/images.xml";
private var imgHolderHT:int = 311;
private var imgHolderWT:int = 673;
private var imgHolder:MovieClip = new MovieClip;
private var spMainDataHolder:Sprite = new Sprite();
private var aData:Array = new Array;
private var numImgLoad:int = 0;
private var aImages:Array = new Array;
private var timer:Timer = new Timer(6000);
private var slideNum:int = 1;
var textFormat:TextFormat = new TextFormat();
public function Main():void
{
pt = this;
pt.addChild(pt.spMainDataHolder);
pt.spMainDataHolder.addChild(pt.imgHolder);
initApp();
}
private function initApp():void
{
var urlLoader:URLLoader = new URLLoader(new URLRequest(pt.XML_FILE_PATH));
urlLoader.addEventListener(Event.OPEN , fnUrlLoadingStart);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR , fnUrlIOError);
urlLoader.addEventListener(Event.COMPLETE , fnUrlLoaded);
}
private function fnUrlLoadingStart(evt:Event)
{
trace("url Loader open event")
}
private function fnUrlIOError(evt:Event):void
{
trace("url Loader error event");
}
private function fnUrlLoaded(evt:Event):void
{
var xml:XML = new XML(evt.target.data);
var slideList:XMLList = xml.img;
var len:int = slideList.length();
for (var i:int = 0; i < len; i++)
{
var obj:Object = new Object;
obj.imgSource = slideList.imgSource[i].toString();
obj.imgTitle = slideList.imgTitle[i] ;
obj.imgDescription = slideList.imgDescription[i];
obj.TitlePosX = slideList.imgTitle[i].@xPos;
obj.TitlePosY = slideList.imgTitle[i].@yPos;
obj.DescriptionPosX = slideList.imgDescription[i].@xPos;
obj.DescriptionPosY = slideList.imgDescription[i].@yPos;
aData.push(obj);
}
fnStartLoadingContent()
}
private function fnStartLoadingContent():void
{
var obj:Object = pt.aData[pt.numImgLoad];
var imgPath:String = obj.imgSource;
var imgLdr:Loader = new Loader();
imgLdr.load(new URLRequest(imgPath));
trace(imgPath)
imgLdr.contentLoaderInfo.addEventListener(Event.OPEN , fnLoadingStart);
imgLdr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS , fnImageProgress);
imgLdr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR , fnImageIOError);
imgLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, fnImageLoaded);
}
private function fnLoadingStart(evt:Event):void
{
trace("img loading start");
}
private function fnImageProgress(evt:ProgressEvent):void
{
trace("img progress event");
}
private function fnImageIOError(evt:IOErrorEvent):void
{
trace("img loading error");
}
private function fnImageLoaded(evt:Event):void
{
pt.numImgLoad ++;
var _ldr:Loader = evt.target.loader as Loader;
pt.aImages.push(_ldr);
if(pt.numImgLoad == 2)
{
var obj:Object = pt.aData[0];
createChildren(pt.aImages[0],obj)
pt.timer.start();
pt.timer.addEventListener(TimerEvent.TIMER , fnChangeSlide);
}
trace(pt.aData.length);
if(numImgLoad > pt.aData.length-1 )
{
return;
}
fnStartLoadingContent();
}
private function fnChangeSlide(event:TimerEvent):void
{
pt.slideNum ++;
trace(pt.aImages.length)
if(pt.slideNum > pt.aImages.length )
{
pt.slideNum = 1;
}
var obj:Object = pt.aData[pt.slideNum-1];
createChildren(pt.aImages[pt.slideNum-1],obj)
}
private function createChildren(img:Loader,obj:Object):void
{
textFormat.size = 20;
textFormat.color = 0xFFFFFF;
var tempSprit:MovieClip = new MovieClip;
tempSprit.addChild(img);
/*var txtTitle:TextField = new TextField;
txtTitle.text = obj.imgTitle;
trace("posDes "+obj.DescriptionPosY)
txtTitle.x = obj.TitlePosX;
txtTitle.y = obj.TitlePosY;
txtTitle.setTextFormat(textFormat);
tempSprit.addChild(txtTitle);
var txtDescription:TextField = new TextField;
txtDescription.text = obj.imgDescription;
txtDescription.x = obj.DescriptionPosX;
txtDescription.y = obj.DescriptionPosY;
txtDescription.setTextFormat(textFormat);
tempSprit.addChild(txtDescription);*/
pt.imgHolder.addChild(tempSprit);
pt.imgHolder.height = pt.imgHolderHT;
pt.imgHolder.width = pt.imgHolderWT;
if(pt.imgHolder.numChildren > 1)
{
var aa:MovieClip = pt.imgHolder.getChildAt(0) as MovieClip;
setTransout(aa)
}
setTrans(tempSprit);
}
//Regular,Strong,Back,None
//flash.easing.Regular.easeOut, Regular.easeInOut,Regular.easeIn same for all
private function setTrans(mcSel:MovieClip):void
{
TransitionManager.start(mcSel, {type:Fade, direction:Transition.IN, duration:2, easing:Regular.easeIn});
}
private function setTransout(mcSel:MovieClip):void
{
var tm:TransitionManager = new TransitionManager(mcSel)
tm.addEventListener ( "allTransitionsOutDone", TriggerTransOut );
tm.startTransition({type:Fade, direction:Transition.OUT, duration:2, easing:Regular.easeIn});
}
private function TriggerTransOut(e:Event):void
{
pt.imgHolder.removeChildAt(0);
}
}
}
Tuesday, February 2, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment