actionscript 3 - Dynamic Gallery to show download and progress bar in as3 -
my flash project has specific task show dynamic gallery items based on xml list , there download option available each gallery item.
for made movieclip (imagetile) thumbnail, title, progressbar & progresstext shown below.
i have 2 classes named 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; (var i:uint = 0; < total; i++) { tile = new imagetile(); wall.addchild(tile); tile.x = % 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") 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] imagetile; var image:bitmap = loader.content 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 code
public var mc_loaded : movieclip = main.gameinstance.tile.getchildbyname("mc_loaded") movieclip, mc_progress : movieclip = main.gameinstance.tile.getchildbyname("mc_progress") movieclip, txt_prog : textfield = main.gameinstance.tile.getchildbyname("txt_prog") textfield; public function downloadfile(url:string) : void { /// download 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 finished mc_loaded.scalex = 0; // want use imagetile element txt_prog.text = "download finished"; } public function onzipcomplete(evt:flash.events.event):void { txt_prog.text = "download finished"; }
the download works fine, can not progress bar , progress text every tile created.
i got answer remove ontileclick(url:string) function main.as
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 imagetile; txt_prog = tile.getchildbyname("txt_prog") textfield; mc_loaded = tile.getchildbyname("mc_loaded") 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 finished mc_loaded.scalex = 0; // want use imagetile element txt_prog.text = "download finished"; } public function onzipcomplete(evt:flash.events.event):void { txt_prog.text = "download finished"; }
Comments
Post a Comment