Hi- I’ve used Flash (with AS2) for several years and I’m trying to make the jump to AS3… and I’m struggling (mostly because of my limited amount of time to really dive into it). Anyway, I have a photogallery that I like that I got from a tutorial and I’m trying to add the ability to display a caption. I’ve gotten it to display the caption only in an error message- so it’s seeing the caption… I’m just doing something horribly wrong with trying to get it to display. Below is the code- I’ll add in comments on what I added to the code. I’m an AC3 newbie- so I’d appreciate any help I can get.
This is the error- which I realized has something to do with adding an array to the display list- which is a no-no… but I’m having trouble figuring out how to fix that…
Thanks a ton!
Here’s the error…
TypeError: Error #1034: Type Coercion failed: cannot convert “Some lamp on the ground” to flash.display.DisplayObject.
at photo_gallery_fla::MainTimeline/fileLoaded()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
Here is a sample of my XML
<?xml version=“1.0” encoding=“utf-8”?>
<images>
<image>
<url>pics/img_1.png</url>
<big_url>big_pics/img_1.png</big_url>
<caption>Some lamp on the ground</caption>
</image>
<image>
<url>pics/img_2.png</url>
<big_url>big_pics/img_2.png</big_url>
<caption>fsdfsdfaafdfdfdfd</caption>
</image>
… it goes on from there… the XML is working fine…
Here’s the actionscript…
import fl.containers.UILoader;
import caurina.transitions.*;
//---------loading the external xml file-------
var urlRequest:URLRequest = new URLRequest(“pics.xml”);
var urlLoader:URLLoader = new URLLoader();
var myXML:XML = new XML();
var xmlList:XMLList;
myXML.ignoreWhitespace = true;
urlLoader.addEventListener(Event.COMPLETE,fileLoaded);
urlLoader.load(urlRequest);
//--------holds the paths to the thumbnails-------
var arrayURL:Array = new Array();
//--------holds the paths to the big photos-------
var arrayName:Array = new Array();
//--------added by me! holds the captions-------
var arrayCaption:Array = new Array();
//--------holds the thumbnail objects-------
var holderArray:Array = new Array();
//--------represents the number of collumns-------
var nrColumns:uint = 5;
//-------represents the container of our gallery
var sprite:Sprite = new Sprite();
addChild(sprite);
var thumb:Thumbnail;
//-------- the thumbnails container-------
var thumbsHolder:Sprite = new Sprite();
sprite.addChild(thumbsHolder);
//-------- the photoLoader container-------
var loaderHolder:Sprite = new Sprite();
loaderHolder.graphics.beginFill(0xffffff,1);
loaderHolder.graphics.drawRect(0,0,550,330);
loaderHolder.graphics.endFill();
loaderHolder.x = 1000;
loaderHolder.y = 10;
sprite.addChild(loaderHolder);
//--------added by me! the captionHolder container-------
var captionHolder:Sprite = new Sprite();
captionHolder.graphics.beginFill(0xffffff,1);
captionHolder.graphics.drawRect(0,0,250,130);
captionHolder.graphics.endFill();
captionHolder.x = 100;
captionHolder.y = 10;
sprite.addChild(captionHolder);
//-------- loads the big photo-------
var photoLoader:UILoader = new UILoader();
photoLoader.width = 540;
photoLoader.height = 320;
photoLoader.y = 5;
photoLoader.x = 5;
photoLoader.buttonMode = true;
photoLoader.addEventListener(MouseEvent.CLICK,onClickBack);
loaderHolder.addChild(photoLoader);
/* we loop through the xml file
populate the arrayURL, arrayName and position the thumbnalis*/
function fileLoaded(event:Event):void {
myXML = XML(event.target.data);
xmlList = myXML.children();
for (var i:int=0; i<xmlList.length(); i++) {
var picURL:String = xmlList*.url;
var picName:String = xmlList*.big_url;
var picCaption:String = xmlList*.caption;
arrayURL.push(picURL);
arrayName.push(picName);
arrayCaption.push(picCaption);
holderArray* = new Thumbnail(arrayURL*,i,arrayName*);
holderArray*.addEventListener(MouseEvent.CLICK,onClick);
holderArray*.name = arrayName*;
holderArray*.buttonMode = true;
if (i<nrColumns) {
holderArray*.y = 65;
holderArray*.x = i*110+65;
} else {
holderArray*.y = holderArray[i-nrColumns].y+110;
holderArray*.x = holderArray[i-nrColumns].x;
}
thumbsHolder.addChild(holderArray*);
//-----------added by me!-------
captionHolder.addChild(arrayCaption*);
}
}
//----handles the Click event added to the thumbnails–
function onClick(event:MouseEvent):void {
photoLoader.source = event.currentTarget.name;
Tweener.addTween(thumbsHolder, {x:-650, time:1, transition:“easeInElastic”});
Tweener.addTween(loaderHolder, {x:10, time:1, transition:“easeInElastic”});
Tweener.addTween(thumbsHolder, {alpha:0, time:1, transition:“linear”});
Tweener.addTween(loaderHolder, {alpha:1, time:1, transition:“linear”});
}
//----handles the Click event added to the photoLoader----
function onClickBack(event:MouseEvent):void {
Tweener.addTween(thumbsHolder, {x:0, time:1, transition:“easeInElastic”});
Tweener.addTween(loaderHolder, {x:1000, time:1, transition:“easeInElastic”});
Tweener.addTween(thumbsHolder, {alpha:1, time:2, transition:“linear”});
Tweener.addTween(loaderHolder, {alpha:0, time:2, transition:“linear”});
}
Any ideas?
Thanks! :sen: