Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing parameters to function

Status
Not open for further replies.

MJB3K

Programmer
Jul 16, 2004
524
0
0
GB
Hi how can i adjust the code below to pass the variables to the function go()? I not quite sure on how to do it... What i am trying to acheive is that each button will goto a different place, but i want one function to handle it.
Code:
import flash.net.*;

function go (event:MouseEvent) {
	//trace(eventObject.name);
	var req:URLRequest = new URLRequest(url);
	navigateToURL (req, "_self");
}

//b1.addEventListener (MouseEvent.CLICK, go));
b2.addEventListener (MouseEvent.CLICK, go);
//b3.addEventListener (MouseEvent.CLICK, go("#message"));
any ideas?

Regards,

Martin

Computing Design And Services:
 
Instead of passing parameters into the function, why don't you assign each button a property, and then access this property within the function, like so:

Code:
import flash.net.*;

function go(e:MouseEvent ) {
    trace (e.target._message);
    var req:URLRequest = new URLRequest("");
    navigateToURL (req, "_self");
}

b1._message = "THIS IS B1";
b2._message = "THIS IS B2";
b3._message = "THIS IS B3";
b1.addEventListener (MouseEvent.CLICK, go);
b2.addEventListener (MouseEvent.CLICK, go);
b3.addEventListener (MouseEvent.CLICK, go);

There's more than one way to go from a to b............



A computer always does what you tell it to, but rarely does what you want it to.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top