I am from a php jquery background and i am currently getting to grips with flash as3 just not sure how to pass values to eventlistner function say i have the following.
for (var i:uint = 0; i < asteroids.length; i++)
{
asteroids[i].x = Math.random() * 450;
asteroids[i].y = Math.random() * 450;
asteroids[i].addEventListener(MouseEvent.MOUSE_UP, changeValue);
}
public function changeValue(event:MouseEvent):void
{
playSound(anote);
trace(event.currentTarget);
}
each asteroid that i addeventlistner in the loop i need to pass a different value to the function the var anote?
jquery i would do.
$(".asteroids").click(function() {
// or something similar
var anote = $(this).attr('href');
playSound(anote);
return false;
});
Can someone point me in the right direction.
I suggest making a class for your Asteroid instances (assuming that’s what’s in the
asteroidsarray). Each of those Asteroids could have ananoteproperty with different values (this closely reflects your.asteroidselementshrefattribute.And then:
Ideally, your Asteroid class would also contain the code in your example and reference whichever class deals with the
playSound()method.The other option is to create your own event class with the
anoteproperty that you can set at dispatch and work with. The process is quite lengthy, so here’s a link to one of my previous answers with an in-depth explanation of implementing that: