Skip to main content
Inspiring
May 14, 2010
Question

Movieclips acting as buttons questions

  • May 14, 2010
  • 1 reply
  • 500 views

I have 4 mc's that are acting as btns inside an mc on the main timeline

code is below

newolivefour_mc.buttonMode=true
newolivefour_mc.addEventListener(MouseEvent.ROLL_OVER,buttonOverfour);
newolivefour_mc.addEventListener(MouseEvent.ROLL_OUT,buttonOutfour);


function buttonOverfour(e:MouseEvent):void
{
    e.currentTarget.gotoAndPlay("over")
}

function buttonOutfour(e:MouseEvent):void
{
    e.currentTarget.gotoAndPlay("out")
}

there are 3 other mc/btns and all come up at different frames in  mainbranch_mc (mainbranch_mc is on the main timeline)

first question, if I add the above codes to each mc at the beginning or end of mainbranch_mc I get a null error, so the only way I do not is if I add actions to the frames the buttons start in. (is this correct?)

second question, since btn mode is true I do not need to change the mc properties from mc to button correct?

last question, since newolivefour_mc and the 3 other btns (which I did not list are all inside the branch_mc timeline) how and where do I code so the btns when released to getURL's

any help??

RD

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
May 14, 2010

1.  you can't apply code to an object that doesn't exist when the code executes.

2.  never change an object from one type to another in the properties panel.  i have no idea why that option exists.

3:

newolivefour_mc.addEventListener(MouseEvent.CLICK,buttonClickfour);


function  buttonClickfour(e:MouseEvent):void
{
   navigateToURL(new URLRequest("http://www.adobe.com"));
}

or even better, so you only need one click function for all your buttons:

newolivefour_mc.addEventListener(MouseEvent.CLICK,buttonClick);

newolivefour_mc.urlS="http://www.adobe.com"


function  buttonClick(e:MouseEvent):void
{
    navigateToURL(new URLRequest(e.currentTarget.urlS));
}

mentlityAuthor
Inspiring
May 14, 2010

Worked like a charm thanks, one question though.

Since the mc/btns are inside branch_mc and the codes were put on the layer inside branch _mc I would have thought that for the btns to function I would have to target the branch_mc for this to work. I like to know these things so if I come across again.

thx 4 the help.

RD

kglad
Community Expert
Community Expert
May 14, 2010

it doesn't matter what you call branch_mc.  the library movieclip that you dragged to the stage to create branch_mc could be dragged to the stage repeatedly and no further coding would be required to get those buttons to function.  of course, they'll all do the same thing because they have the same code.  no problem with the rollover/rollout code but the click code probably won't work the way you want.

because of that and mostly because it's poor coding style to place code in a nested movieclip, you should apply your code to branch_mc.whateverbutton on the main timeline where branch_mc is instantiated.

p.s.  please mark this thread as answered, if you can.