Skip to main content
juresti
Known Participant
December 1, 2009
Answered

Need Function for 20 Buttons

  • December 1, 2009
  • 2 replies
  • 1087 views

The Buttons are on stage with Instance names ButID10 - ButID32.

Can anyone help with this? Any help is appreciated. DO I need to create an array? Thank you.

The code below I know is wrong:


for(var i:uint=10;i<32;i++){
        Chart06["ButID"+i.toString()].addEventListener(MouseEvent.MOUSE_OVER, buttonIDChart06Over, false, 0, true);
        Chart06["ButID"+i.toString()].addEventListener(MouseEvent.MOUSE_OUT, buttonIDChart06Out, false, 0, true);
       
    }

function buttonIDChart06Over(e:MouseEvent){trace(i);
    popUp01.x = Chart06["ButID"+i.toString()].x;
    popUp01.y = Chart06["ButID"+i.toString()].y;
    addChild(popUp01);
    popUp01.PopUpTextID00.htmlText=popupList[i-1];
    popUp01.filters = [myDropShadowFilter];
    }
function buttonIDChart06Out(e:MouseEvent){
    removeChild(popUp01);
    }

This topic has been closed for replies.
Correct answer kglad

yes, it does.  but the value of i changes from when the button's listener is added to when you check it in the listener function.

if your 20 buttons are movieclip buttons use:



for(var i:uint=10;i<32;i++){

Chart06["ButID"+i.toString()].ivar=i;
        Chart06["ButID"+i.toString()].addEventListener(MouseEvent.MOUSE_OVER, buttonIDChart06Over, false, 0, true);
        Chart06["ButID"+i.toString()].addEventListener(MouseEvent.MOUSE_OUT, buttonIDChart06Out, false, 0, true);
       
    }

function buttonIDChart06Over(e:MouseEvent){

trace(e.currentTarget.ivar);
    popUp01.x = Chart06["ButID"+e.currentTarget.ivar.toString()].x;
    popUp01.y = Chart06["ButID"+e.currentTarget.ivar.toString()].y;

    addChild(popUp01);
   popUp01.PopUpTextID00.htmlText=popupList[e.currentTarget.ivar-1];
    popUp01.filters = [myDropShadowFilter];
    }
function buttonIDChart06Out(e:MouseEvent){
    removeChild(popUp01);
    }

2 replies

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
December 1, 2009

yes, it does.  but the value of i changes from when the button's listener is added to when you check it in the listener function.

if your 20 buttons are movieclip buttons use:



for(var i:uint=10;i<32;i++){

Chart06["ButID"+i.toString()].ivar=i;
        Chart06["ButID"+i.toString()].addEventListener(MouseEvent.MOUSE_OVER, buttonIDChart06Over, false, 0, true);
        Chart06["ButID"+i.toString()].addEventListener(MouseEvent.MOUSE_OUT, buttonIDChart06Out, false, 0, true);
       
    }

function buttonIDChart06Over(e:MouseEvent){

trace(e.currentTarget.ivar);
    popUp01.x = Chart06["ButID"+e.currentTarget.ivar.toString()].x;
    popUp01.y = Chart06["ButID"+e.currentTarget.ivar.toString()].y;

    addChild(popUp01);
   popUp01.PopUpTextID00.htmlText=popupList[e.currentTarget.ivar-1];
    popUp01.filters = [myDropShadowFilter];
    }
function buttonIDChart06Out(e:MouseEvent){
    removeChild(popUp01);
    }

juresti
jurestiAuthor
Known Participant
December 1, 2009

ok this is helping. The thing is this is for an org chart. The popup with information will be at different coordinates

  popUp01.x = Chart06["ButID"+e.currentTarget.ivar.toString()].x;
  popUp01.y = Chart06["ButID"+e.currentTarget.ivar.toString()].y;

Can I take the Chart06["ButID"+e.currentTarget.ivar.toString()].y coordinate and subtract a number from it or add?

Like

[(Chart06["ButID"+e.currentTarget.ivar.toString()]) - (200)].y

PLus each popup has different text pulled from the XMLlist

popUp01.PopUpTextID00.htmlText=popupList[1];

So depending on which butoon is rolled over differerent text will come up.

I know this is confusing I'm trying to sort it out.

juresti
jurestiAuthor
Known Participant
December 1, 2009

Chart06["ButID"+i.toString()].ivar=i;

Can you tell me what that is doing?

When you have time thank you.

I guess I could use IF Else Statements for the different buttons within the one function?

kglad
Community Expert
Community Expert
December 1, 2009

are your buttons on the timeline of a movieclip with instance name Chart06?  if so, your code would work.  if not, why are you using Chart06?

juresti
jurestiAuthor
Known Participant
December 1, 2009

yea they are in Chart06. But does the code

actually set evnt listeners for each button?


juresti
jurestiAuthor
Known Participant
December 1, 2009

It is setting event listeners. Its just that I have to place a pop up at specific x and y coordinates and that is what I am doing wrong also. I am still working on it though.