Current location: Hot Scripts Forums » General Web Coding » Flash & ActionScript » Passing a variable to an event listener


Passing a variable to an event listener

Reply
  #1 (permalink)  
Old 03-29-10, 04:04 AM
zitwep zitwep is offline
Wannabe Coder
 
Join Date: Aug 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Passing a variable to an event listener

I'm pretty new to AS 3.0 and I'm at a loss as to how I should go around using a variable in a function called by the event listener. I have this first function which goes through an xml file and adds a new instance of a movie for every element in the xml like so:
Code:
function rssLoaded(e:Event):void{
	rssXML = XML(rssLoader.data);
	//trace(rssXML);
	var pos:int = 140;
	var index1:int = 0;
	
	for(var item:String in rssXML.feed){
		var newRss:rssContainer = new rssContainer();
		newRss.name = "rss" + rssXML.feed[item].name;
		
		newRss.x = 51;
		newRss.y = pos;
		this.addChild(newRss);
		newRss.feedName.text = rssXML.feed[item].name;
		//liFeeds.addItem( {label:rssXML.feed[item].name} );
		
		pos += 70;
		index1++;
		newRss.addEventListener(MouseEvent.CLICK, selectLog);
	}
}
As you can see, it creates a new event listener for each item. How would I use the counter, index1, in selectLog? I'm also thinking that the counter's value will always its last, how would I pass the proper value?

Quote:
function selectLog(e:Event):void {
trace(index1);
}
I tried having a variable in the movie clip, and making it equal in each loop to the counter and then access it with e.target.count, but when I clicked on the textfield of the movie clip, it gave me an error.

Thanks a bunch
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Javascript Variable to PHP watadude PHP 4 01-15-11 06:44 PM
AS3 Event Listener for a seperate class mjjwatson Flash & ActionScript 0 11-13-09 10:04 AM
[SOLVED] Handle event listener zoliky JavaScript 3 06-02-08 01:44 PM
Passing around $_FILES variable eddyvlad PHP 0 02-02-06 01:21 AM


All times are GMT -5. The time now is 06:52 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.