Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Passing Array value in EventListener

New Here ,
Jul 19, 2016 Jul 19, 2016

Hi All, been at this for a while now and can't see the wood for the trees. Is there a way to pass a value through an EventListener so that the array referenced within the function changes value?

var i=int;

btn_US.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler,i=3);

function mouseOverHandler(e:MouseEvent, i):void {

txt_CountryName.text = country;

txt_GoverningBody.text = governingbody;

}

I simply can't see to pass the i value...

Any help would be greatly appreciated.

Mike

TOPICS
ActionScript
325
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jul 19, 2016 Jul 19, 2016

From your description it sounds like you are attempting to use one function to work with a bunch of buttons to give you a unique result on each rollover. If that's correct then you may get the result that you want by using an array that contains the instance names of each of the rollover buttons. Then you can use the event target to give you the values from the other two arrays.

Something like this:

var buts:Array = new Array(but1,but2,but3);

var cName:Array = new Array("A","B","C");

var cBody:Array

...
Translate
LEGEND ,
Jul 19, 2016 Jul 19, 2016

From your description it sounds like you are attempting to use one function to work with a bunch of buttons to give you a unique result on each rollover. If that's correct then you may get the result that you want by using an array that contains the instance names of each of the rollover buttons. Then you can use the event target to give you the values from the other two arrays.

Something like this:

var buts:Array = new Array(but1,but2,but3);

var cName:Array = new Array("A","B","C");

var cBody:Array = new Array("D","E","F");

for(var i in buts) {

  buts.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);

}

function mouseOverHandler(e:MouseEvent):void {

  var thisOne:int = buts.indexOf(e.target);

  txt_CountryName.text = country[thisOne];

  txt_GoverningBody.text = governingbody[thisOne];

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 19, 2016 Jul 19, 2016

Thanks robdillon, this actually streamlined the whole process!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 19, 2016 Jul 19, 2016
LATEST

You're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines