动态图库在 as3 中显示下载和进度条

Dynamic Gallery to show download and progress bar in as3

我的 Flash 项目有特定的任务来显示基于 XML 列表的动态画廊项目,并且每个画廊项目都有一个可用的下载选项。

为此,我制作了一个带有缩略图、标题、ProgressBar 和 ProgressText 的动画片段 (imageTile),如下所示。

我有两个 类 名为 Main.as 和 FileRef.as

Main.as

        var tileMap:Dictionary = new Dictionary();
        public var tile:ImageTile;

        addChild(wall);
        wallWidth = wall.width;
        wallHeight = wall.height;
        var columns:Number;
        var my_x:Number;
        var my_y:Number;
        var my_thumb_width:Number;
        var my_thumb_height:Number;
        var images:XMLList;
        var total:Number;
        var swipe:Number = 0;

        var myXMLLoader:URLLoader = new URLLoader();
        myXMLLoader.load(new URLRequest("gallery.xml"));
        myXMLLoader.addEventListener(Event.COMPLETE, processXML);

    function processXML(e:Event):void {
        myXML = new XML(e.target.data);

        images = myXML.IMAGE;
        total = images.length();


        myXMLLoader.removeEventListener(Event.COMPLETE, processXML);
        myXMLLoader = null;


        var loader:Loader;
        for (var i:uint = 0; i < total; i++) {
        tile = new ImageTile();
        wall.addChild(tile);

        tile.x = i % 3 * 400 + 180;
        tile.y = Math.floor(i / 3) * 650 + 250;

        var imageName:String = images[i].@FULL;
        path = images[i].@Path;
        var title:String = images[i].@Title;
        **var caption:TextField = tile.getChildByName("caption_tf") as TextField;**
        caption.text = title;
        tile.addEventListener(MouseEvent.CLICK, onTileClick(path));
        loader = new Loader();
        loader.load(new URLRequest("images/" + imageName));
        tileMap[loader] = tile;
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoad);
    }
//trace(myXML);
}


    var tileMap:Dictionary = new Dictionary();


function onImageLoad(e:Event):void {
    var loader:Loader = e.target.loader;
    var tile:ImageTile = tileMap[loader] as ImageTile;
    var image:Bitmap = loader.content as Bitmap;
    image.x = -100;
    image.y = -100;
    image.width=366;
    image.height=418;
    var textField:DisplayObject = tile.getChildByName("caption_tf");
    var textFieldDepth:int = tile.getChildIndex(textField);
    tile.addChildAt(image, textFieldDepth);
    tileMap[loader] = null;
    image.smoothing = true;
}


function onTileClick(url:String):Function {
     return function(me:MouseEvent):void {          

        path = url;
        var download:FileRef = new FileRef();
         download.downloadFile(path);
}

FileRef.as代码

public var mc_loaded   : MovieClip = Main.gameInstance.tile.getChildByName("mc_loaded") as MovieClip,
           mc_progress : MovieClip = Main.gameInstance.tile.getChildByName("mc_progress") as MovieClip,
           txt_prog    : TextField = Main.gameInstance.tile.getChildByName("txt_prog") as TextField;

public function downloadFile(url:String) : void
        {
   /// Download the gallery item codes using url
}

public function progressHandler( event : ProgressEvent ) : void
        {       
            //mc_loaded.scaleX = (event.bytesLoaded / event.bytesTotal) ;
        }

        public function completeHandler( event : Event ) : void
        {
            //reset progress bar after download is finished
            mc_loaded.scaleX = 0;  // I want to use the imageTile element
            txt_prog.text = "download finished";
        }

        public function OnZipComplete(evt:flash.events.Event):void
        {
         txt_prog.text = "download finished";
        }

下载工作正常,但我无法获取创建的每个磁贴的进度条和进度文本。

我得到了答案 从 Main.as

中删除 onTileClick(url:String) 函数

Main.as

function processXML(e:Event):void {
//// Codes /////
//// Codes /////
var download:FileRefTut = new FileRefTut();
tile.addEventListener(MouseEvent.CLICK, download.downloadFile(path));
}

FileRef.as

public var txt_prog:TextField, mc_loaded:MovieClip; 

public function downloadFile(url:String):Function {
         return function(me:MouseEvent):void {

        var tile:ImageTile = me.currentTarget as ImageTile;
        txt_prog = tile.getChildByName("txt_prog") as TextField;
        mc_loaded = tile.getChildByName("mc_loaded") as MovieClip;

    }

public function progressHandler( event : ProgressEvent ) : void
        {       
            mc_loaded.scaleX = (event.bytesLoaded / event.bytesTotal) ;
        }

    public function completeHandler( event : Event ) : void
    {
        //reset progress bar after download is finished
        mc_loaded.scaleX = 0;  // I want to use the imageTile element
        txt_prog.text = "download finished";
    }

    public function OnZipComplete(evt:flash.events.Event):void
    {
     txt_prog.text = "download finished";
    }