Trouble Loading thumbnails from XML in Flash as3.0 -
i have made gallery script loads xml large image, text, , 3 thumbnails. having trouble getting thumbnails load reason. have 3 thumbnails should previous image, current image, , next image. except when click on current image should load random image. buttons work if try load thumbnails. don't appear.
to load thumbnails have created loop array of thumbnails , number of image recorded variable noofimage. load other thumbnails subtracting 1 noofimage if prev button clicked(mousewheel down or key dwn or key left) , adding 1 noofimage if next button clicked(wheel , keys...)
when trace variables thumbnail number seem correct @ times , other times receiving errors.
for ex. if load swf , click next. previous image "4294967295" , next 1 outputs "error #2044: unhandled ioerrorevent:. text=error #2035: url not found."
if value of nextimage = 1 dont see why isn't loading. , why giving weird number should 0? can not tell if problem if statements use handle noofimage variables or if has loaders or thumbnail containers... keep trying can think of. original version loaded thumbs loop , worked having trouble making them clickable buttons , decided make simpler.
here example of how far i've gotten script. http://soulseekrecords.org/psysci/portfolio/portfolio.swf
below code sorry if messy or unclear. try best.
//import tweening files import com.greensock.*; import com.greensock.easing.*; import flash.display.movieclip; import flash.events.event; import flash.text.textfield; import flash.text.textformat; import fl.controls.uiscrollbar; import flash.display.sprite; import com.greensock.plugins.*; tweenplugin.activate([tintplugin]); //create sprite background var backgrnd:sprite = new sprite(); //create array of image names var imagenames:array = new array(); //create array of text descriptions var desctext:array = new array(); //create array dice images var dinames:array = new array(); //variable total number of images var totalimages:uint = imagenames.length; //add sprite variables var thumb:sprite = new sprite(); var thumb2:sprite = new sprite(); var thumb3:sprite = new sprite(); // create loaders var smimageloader:loader = new loader(); var smimageloader2:loader = new loader(); var smimageloader3:loader = new loader(); //create variable load large image var bigimageloader:loader = new loader(); //create variables image # var noofimage:int; var previmage:uint; var nextimage:uint; //create random number var var randomnumber:uint; previmage = 0; nextimage = totalimages; noofimage = -1; // add sprite display list addchild(thumb); addchild(thumb2); addchild(thumb3); thumb.graphics.beginfill(0xffffff); thumb.graphics.drawrect(25, 325, 75, 75); thumb.graphics.endfill(); thumb2.graphics.beginfill(0xffffff); thumb2.graphics.drawrect(125, 325, 75, 75); thumb2.graphics.endfill(); thumb3.graphics.beginfill(0xffffff); thumb3.graphics.drawrect(225, 325, 75, 75); thumb3.graphics.endfill(); thumb.alpha = 1; thumb2.alpha = 1; thumb3.alpha = 1; thumb.addchild(smimageloader2); thumb2.addchild(smimageloader3); thumb3.addchild(smimageloader); smimageloader.y = 325; smimageloader2.y = 325; smimageloader3.y = 325; smimageloader.x = 25; smimageloader2.x = 125; smimageloader3.x = 225; //scroll variables var scrollbaradd:boolean = false; var scrollbar:uiscrollbar = new uiscrollbar(); var myxml:xml; var myloader:urlloader = new urlloader(); myloader.load(new urlrequest("portfolio.xml")); myloader.addeventlistener(event.complete, processxml); function processxml(e:event) { myxml = new xml (e.target.data); for(var i:uint = 0; < myxml.img.length() ; i++) { imagenames.push(myxml.img[i].text()); desctext.push(myxml.txt[i].text()); dinames.push(myxml.imgd[i].text()); } totalimages = imagenames.length; } //add background color sprite addchild(backgrnd); setchildindex(backgrnd,0); //add background properties backgrnd.graphics.beginfill(0xffffff); backgrnd.graphics.drawrect(0, 0, 900, 500); //add background image var backrobe:loader = new loader(); addchild(backrobe); backrobe.x = 0; backrobe.y = 0; backrobe.load(new urlrequest("images/background.png")); //add bigimageloader display list addchild(bigimageloader); bigimageloader.x = 225; bigimageloader.y = 25; //add buttons fwd , rev var forward:fwd = new fwd(); var reverse:rev = new rev(); addchild(forward); addchild(reverse); forward.x = 155; forward.y = 365; reverse.x = 33; reverse.y = 365; forward.addeventlistener(mouseevent.mouse_over, mseovr); reverse.addeventlistener(mouseevent.mouse_over, mseovr2); forward.addeventlistener(mouseevent.mouse_out, mseout); reverse.addeventlistener(mouseevent.mouse_out, mseout2); function mseovr (event:mouseevent){ tweenlite.to(forward, .1, {alpha:.5}); } function mseovr2 (event:mouseevent) { tweenlite.to(reverse, .1, {alpha:.5}); } function mseout (event:mouseevent){ tweenlite.to(forward, .1, {alpha:1}); } function mseout2 (event:mouseevent) { tweenlite.to(reverse, .1, {alpha:1}); } //variable key press function var rkey:uint = 39; var lkey:uint = 37; var ukey:uint = 38; var dkey:uint = 40; //create textfield var mytext:textfield = new textfield(); //add text box display list addchild(mytext); mytext.width = 200; mytext.height = 340; mytext.x = 5; mytext.y = 5; mytext.wordwrap = true; mytext.multiline = true; mytext.selectable = true; var format:textformat = new textformat(); format.font = "arial"; format.color = 0xffffff; format.size = 20; format.underline = false; mytext.defaulttextformat = format; //add button var hotspot:hotspot = new hotspot(); //add button display list addchild(hotspot); //set button x , y position hotspot.x = 92; hotspot.y = 367; hotspot.alpha = 0; hotspot.width = 50; hotspot.height = 50; //set buttonmode hotspot.buttonmode = true; //make sure clicks register thumb (not inner contents) hotspot.mousechildren = false; //add click listener button hotspot.addeventlistener(mouseevent.mouse_down, buttonclickhandler); hotspot.addeventlistener(mouseevent.mouse_over, mouseoverhotspot); hotspot.addeventlistener(mouseevent.mouse_out, mouseouthotspot); function mouseoverhotspot(event:mouseevent){ tweenlite.to(hotspot, .1, {alpha:.5}); } function mouseouthotspot(event:mouseevent){ tweenlite.to(hotspot, 1, {alpha:0}); } function buttonclickhandler (event:mouseevent) { randomnumber = math.random()*3; noofimage = randomnumber; loadersnlist(); } stage.addeventlistener(mouseevent.mouse_wheel, upmouse); function upmouse(event:mouseevent) { if (event.delta == 3) { noofimage = noofimage + 1; if (noofimage == totalimages) { noofimage = noofimage - totalimages; } } if (event.delta == -3) { if (noofimage == -1 || noofimage == -2) { noofimage = totalimages; } if (noofimage == 0) { noofimage = noofimage + totalimages; } noofimage = noofimage - 1; } loadersnlist(); } forward.addeventlistener(mouseevent.click, fwdclck); function fwdclck (event:mouseevent) { noofimage = noofimage + 1; if (noofimage == totalimages) { noofimage = noofimage - totalimages; } loadersnlist(); } reverse.addeventlistener(mouseevent.click, revclck); function revclck(event:mouseevent) { if (noofimage == -1 || noofimage == -2) { noofimage = totalimages; } if (noofimage == 0) { noofimage = noofimage + totalimages; } noofimage = noofimage - 1; loadersnlist(); } //key right arrow event stage.addeventlistener(keyboardevent.key_down, keyright); function keyright(event:keyboardevent) { if (event.keycode==rkey || event.keycode==ukey) { noofimage = noofimage + 1; if (noofimage == totalimages) { noofimage = noofimage - totalimages; } loadersnlist(); } } //key left arrow event stage.addeventlistener(keyboardevent.key_down, keyleft); function keyleft(event:keyboardevent){ if (event.keycode==lkey || event.keycode==dkey) { if (noofimage == -1 || noofimage == -2) { noofimage = totalimages; } if (noofimage == 0) { noofimage = noofimage + totalimages; } noofimage = noofimage - 1; loadersnlist(); } } function scrollerthing () { if (mytext.textheight > mytext.height) { scrollbar.scrolltarget = mytext; //assign target of scrollbar textfield scrollbar.height = mytext.height; //make height same textfield scrollbar.move(mytext.x + mytext.width, mytext.y); //move scrollbar righthand side addchild(scrollbar); scrollbar.update(); scrollbaradd = true; } else { if((mytext.textheight < mytext.height) && scrollbaradd == true) { scrollbaradd = false; removechild(scrollbar); } } } function loadersnlist () { bigimageloader.load(new urlrequest("images/" + imagenames[noofimage] ) ); bigimageloader.contentloaderinfo.addeventlistener(event.complete, tweenage); smimageloader.load(new urlrequest("thumbs/" + dinames[noofimage] ) ); smimageloader.contentloaderinfo.addeventlistener(event.complete, tweenage2); previmage = noofimage - 1; nextimage = noofimage + 1; if (previmage <= -1){ previmage = totalimages; } if (nextimage >= totalimages){ nextimage = 0; } trace (previmage); trace (nextimage); smimageloader2.load(new urlrequest("thumbs/" + dinames[previmage] ) ); smimageloader2.contentloaderinfo.addeventlistener(event.complete, tweenage2); smimageloader3.load(new urlrequest("thumbs/" + dinames[nextimage] ) ); smimageloader3.contentloaderinfo.addeventlistener(event.complete, tweenage2); } function tweenage(e:event) { bigimageloader.alpha = 0; tweenlite.to( bigimageloader, 5, {alpha:1, ease:expo.easeout} ); mytext.alpha = 0; tweenlite.to( mytext, 5, {alpha:1} ); mytext.text = string (desctext[noofimage]); scrollerthing(); } function tweenage2 (e:event) { //create variable load small thumbnail url image tweenlite.to( smimageloader, 5, {scalex:.6, scaley:.6, ease:expo.easeout} ); tweenlite.to( smimageloader2, 5, {scalex:.6, scaley:.6, ease:expo.easeout} ); tweenlite.to( smimageloader3, 5, {scalex:.6, scaley:.6, ease:expo.easeout} ); }
you're there in tracing out thumbnail value. next step trace out actual url trying load.
doing show referencing. looks tracking previmage, , setting number of images when less 1. array of thumbnails zero-based though, 3 thumbnails, thumbs @ 0, 1, , 2 , trying load dinames[3].
changing loadersnlist function previmage = totalimages-1; should fix it.
as aside, i'd suggest placing asset creation code in layout function, , once has been added stage calling loader functions pull in data.
Comments
Post a Comment