PDA

View Full Version : linkevent node information



mightyRGB
August 15th, 2007, 07:40 PM
Hi all,

I have an xml file with linkevents written in like this: <a href="event:images/image2.jpg">Image2</a>

when i run my actionscript, the links show up (amongst other text) in a textfield and when clicked trigger linkevents which create popups based on the url given in the xml. Is there any way to get additional information from the corresponding <a> node when a link is clicked? I want to possibly add a different sound for each link, but I'm not sure of what would be the best way of doing this. Any help would be greatly appreciated.

Thanks

mathew.er
August 15th, 2007, 08:06 PM
The even is an instance of flash.events.TextEvent just the the text property set to the part after event: in href attribute. There could be more ways to add more info into that.

1. Store the additional info in some arrays...

var images : Array = ['image1.jpg', 'image2.jpg'];
var sounds : Array = ['sound1', 'sound2']; and the have the href as
<a href="event:0">link</a> where the number will be index of the array items. Here you would access it as

private function linkHandler ( linkEvent : TextEvent ) : void {
var index : int = int ( linkEvent.text );
var image : String = images[index];
var sound : String = sounds[index];
}

2. Store the info in an Obejct or Dictionary

var sounds : Object = {};
sounds["image1.jpg"] = 'sound1';
sounds["image2.jpg"] = 'sound2'; where the part after event: will be the same as those string keys (image1.jpg etc) and you would access the data as
private function linkHandler ( linkEvent : TextEvent ) : void {
var sound : String = sounds[linkEvent.text]
}

3. Have all the info in the href already, just separated by some string

<a href="event:image1.jpg|sound1">link</a> and then get the info by
private function linkHandler ( linkEvent : TextEvent ) : void {
var splitted : Array = linkEvent.text.split ( '|' );
var image : String = splitted[0];
var sound : String = splitted[1];
}

mightyRGB
August 16th, 2007, 01:25 PM
Thanks mathew.er,

I used option 3 and it works well with my code :)