Prindol

DESIGN, HTML5, CSS3, DOM, Jquery, JSON, Actionscript2/3, Linux, IIS

You are not logged in.

#1 2011-08-11 14:34:24

admin
Administrator
Registered: 2011-07-22
Posts: 15

[AS3] XML & IEventDispatcher

import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, xmlLoaded);
var req:URLRequest;
if(!loaderInfo.parameters.XMLurl) {
    req = new URLRequest("rolling.xml");
} else {
    req = new URLRequest(loaderInfo.parameters.XMLurl);
}

loader.load(req);

var arr:Array = new Array();

function xmlLoaded(event:Event):void {
    var xmlData:XML=new XML(event.target.data);
    xmlData.ignoreWhitespace = true;
    var xmlList:XMLList = xmlData.children();
        
    for(var i:int = 0; i < xmlList.length() -1; i++) {
        var target:DisplayObject = this.getChildByName("scene");
        var A:sceneMc = new sceneMc();
        this.addChildAt(A, 0);
        A.name = "scene"+i;
        A.x = 0;
        A.y = 0;
        A.link1 = xmlData.image[i].left.attribute("link");
        A.link2 = xmlData.image[i].right.attribute("link");
        A.alpha = 0;

        arr.push(A);

        var imgLoader:Loader = new Loader(); 
        var imgRequest:URLRequest = new URLRequest (xmlData.image[i].left.attribute("src")); 
        imgLoader.load(imgRequest); 
        imgLoader.x = -10; 
        A.imgLeft.addChild(imgLoader); 
        configureListeners(imgLoader.contentLoaderInfo); 

        var imgLoader2:Loader = new Loader(); 
        var imgRequest2:URLRequest = new URLRequest (xmlData.image[i].right.attribute("src")); 
        imgLoader2.load(imgRequest2); 
        imgLoader2.x = -10; 
        A.imgRight.addChild(imgLoader2); 
        configureListeners(imgLoader2.contentLoaderInfo); 

    }
    arr[0].x = -800;
    arr[1].x = 0;
    arr[2].x = 800;
}

function configureListeners(dispatcher:IEventDispatcher):void {
    dispatcher.addEventListener(Event.COMPLETE, completeHandler);
}

function completeHandler(event:Event):void {
    //var duration:Number = 0.01;
    //event.target.alpha = 1;
    for(var i = 0; i < arr.length ; i++) {
        arr[i].alpha = 1;
        //new Tween(arr[i], "alpha", Strong.easeInOut, 0, 1, duration, true);
    }
}

Offline

Board footer

Powered by FluxBB