Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble Loading thumbnails from XML in Flash as3.0
    text
    copied!<p>I have made a gallery script that loads from xml a large image, text, and 3 thumbnails. I am having trouble getting the thumbnails to load for some reason. I have it so that the three thumbnails should be the previous image, the current image, and the next image. Except when you click on the current image it should load a random image. The buttons work for this but if I try to load thumbnails. They don't appear.</p> <p>To load the thumbnails I have created a for loop for the array of thumbnails and the number of the image is recorded by the variable noOfImage. I then load the other thumbnails by subtracting 1 to noOfImage if the prev button is clicked(mousewheel down or key dwn or key left) and adding 1 to noOfImage if the next button is clicked(wheel and keys...)</p> <p>When I trace what the variables for the thumbnail number is they seem to be correct at times and other times I am receiving errors.</p> <p>For ex. If I load the swf and click next. The previous image is "4294967295" and the next is 1 but it outputs this "Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found."</p> <p>If the value of nextImage = 1 then I dont see why it isn't loading. And why is it giving a weird number for what should be 0? I can not tell if the problem is with the if statements I use to handle the noOfImage variables or if it has something to do with the loaders or thumbnail containers... I keep trying everything I can think of. my original version loaded all the thumbs with a for loop and worked but I was having trouble making them into clickable buttons and decided to make it simpler.</p> <p>here is an example of how far i've gotten with the script. <a href="http://soulseekrecords.org/psysci/portfolio/Portfolio.swf" rel="nofollow">http://soulseekrecords.org/psysci/portfolio/Portfolio.swf</a></p> <p>below is all my code sorry if it is messy or unclear. I try my best.</p> <pre><code>//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 for dice images var dinames:Array = new Array(); //variable for 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 a variable to load the large image var bigImageLoader:Loader = new Loader(); //create variables for the 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 to 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; i &lt; 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 to the display list addChild(bigImageLoader); bigImageLoader.x = 225; bigImageLoader.y = 25; //add buttons fwd and 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 a textField var myText:TextField = new TextField(); //add text box to 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 to display list addChild(hotSpot); //Set button x and y position hotSpot.x = 92; hotSpot.y = 367; hotSpot.alpha = 0; hotSpot.width = 50; hotSpot.height = 50; //set buttonmode hotSpot.buttonMode = true; //make sure all clicks register with the thumb itself (not inner contents) hotSpot.mouseChildren = false; //add click listener to the 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 &gt; myText.height) { scrollBar.scrollTarget = myText; //assign the target of the scrollBar to your textfield scrollBar.height = myText.height; //make the height the same as the textfield scrollBar.move(myText.x + myText.width, myText.y); //Move the scrollbar to the righthand side addChild(scrollBar); scrollBar.update(); scrollBarAdd = true; } else { if((myText.textHeight &lt; myText.height) &amp;&amp; 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 &lt;= -1){ prevImage = totalImages; } if (nextImage &gt;= 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 a variable to 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} ); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload