PDA

View Full Version : XML navigate to url


becca2anne0
10-14-2008, 03:02 PM
XML confuses me to no end. Just when I think I understand, I'm confused again. I followed a tutorial online to make a carousel in AS3. I need to open the link in the XML when a specific image is clicked. I have looked at dozens of posts to this, and I still am getting error after error. help!!

here is my document class:
public class CarouselDoc extends MovieClip {

// on stage of .fla
public var rightAd:MovieClip;
public var leftAd:MovieClip;
//public var right_mc:MovieClip;
//public var left_mc:MovieClip;
public var holder_mc:MovieClip;
public var loading_txt:TextField;

public static const XML_URL:String = "images.xml";

private var carousel:Carousel;
private var imageList:XMLList;
private var numImages:int;
private var currentImage:int = 0;

public function CarouselDoc():void {

carousel = new Carousel(500, 250, 220);
carousel.useBlur = false;
holder_mc.addChild(carousel);

stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
rightAd.addEventListener(MouseEvent.CLICK, leftClickHandler);
leftAd.addEventListener(MouseEvent.CLICK, rightClickHandler);
//right_mc.addEventListener(MouseEvent.CLICK, rightClickHandler);
//left_mc.addEventListener(MouseEvent.CLICK, leftClickHandler);

var uloader:URLLoader = new URLLoader();
uloader.addEventListener(Event.COMPLETE, xmlHandler);
uloader.addEventListener(IOErrorEvent.IO_ERROR, xmlHandler);
uloader.load(new URLRequest(XML_URL));
}

private function xmlHandler(event:*):void {
event.currentTarget.removeEventListener(Event.COMP LETE, xmlHandler);
event.currentTarget.removeEventListener(IOErrorEve nt.IO_ERROR, xmlHandler);
if (event is IOErrorEvent) {
loading_txt.text = "could not load xml file";
} else {
var xml:XML = new XML(event.currentTarget.data);
imageList = xml..image;
numImages = imageList.length();
loadImage();
}
}

private function loadImage():void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, imageHandler);
loader.contentLoaderInfo.addEventListener(IOErrorE vent.IO_ERROR, imageHandler);
loader.load(new URLRequest(imageList[currentImage].toString()));
}

private function imageHandler(event:*):void {
event.currentTarget.removeEventListener(Event.COMP LETE, imageHandler);
event.currentTarget.removeEventListener(IOErrorEve nt.IO_ERROR, imageHandler);
if (event is IOErrorEvent) {
loading_txt.text = "could not load image" + currentImage;
} else {
var image:Loader = event.currentTarget.loader;
carousel.addItem(image);
}

if (++currentImage < numImages){
loadImage();
} else {
loading_txt.text = "";
}
}
/

and my XML file

<menuItems>

<item>
<image>pics/Home Page Classroom Training Static Ad.jpg</image>
<link> http://www.ema-eda.com</link>
</item>

<item>
<image>pics/icon2.jpg</image>
<link> http://www.ema-eda.com</link>
</item>

<item>
<image>pics/test.swf</image>
<link> http://www.ema-eda.com</link>
</item>


</menuItems>

I have also included my source files

Nabren
10-14-2008, 05:28 PM
Perhaps you could provide more info on the errors you are getting? With that, it would be easier to track down the problem.

becca2anne0
10-14-2008, 06:40 PM
well all of that xml works. But I need it to open the browser window and take you to the link of the image, and I have no idea where to put the navigatetoURL or what things I need to add or what things I already have, I'm lost.

runtime
10-16-2008, 08:13 PM
Have you checked the tutorials at Kirupa or gotoandlearn.com on carousels? There is an excellent tutorial on XML on the ladder.

That said, I can give you some concepts to think about.

You need to push the url link (node) into an array. Then you simply need to access that array on press. So just like you set up a variable for images (imageList) you will need to do the same for your URL links.