Groups | Blog | Home
all groups > flash actionscript > march 2007 >

flash actionscript : Movieclip within movieclip


Newbie1234
3/24/2007 5:53:40 PM
I have a movieclip called Room, and within this movieclip, I have another
movieclip called newspaper_mc. When the newspaper image is clicked, newspaper
mc plays hence the code:

newspaper_mc.onRelease = function() {
newspaper_mc.play ()
}

But, newspaper_mc has several buttons and when these buttons are clicked they
play different frames within that movieclip. I put some code for the buttons,
but seems to ignore this code, so when the newspaper is clicked with the mouse,
it plays the next frame and the next because of the code I wrote above.

How do I get the buttons to work?
kglad
3/24/2007 8:12:07 PM
you can't assign mouse handlers to a parent and child movieclip and expect the
child movieclip to respond: the parent movieclip intercepts the mouse events.

to remedy, either code all your mouse handlers at the youngest generation that
needs handlers or use a hitTest for the parent or all the children.
Newbie1234
3/24/2007 8:54:40 PM
So basically, within the movieclip of the movieclip, I need to put the code on
the actual buttons?

So if i click on the button, would the code be:
nextbtn.onRelease = function () {
gotoAndPlay (40)
}
GWD
3/24/2007 9:31:14 PM
no because of what kglad said.

Once you start the newspaper_mc (which is the parent clip for your other
buttons) playing, do you still need to continue to listen for clicks on it .If
you don't need that then try this:

newspaper_mc.onRelease = function() {
newspaper_mc.play ()
delete newspaper_mc.onRelease
}

then you could do something like in your last post.

Newbie1234
3/24/2007 10:28:08 PM
No, I dont need to listen out for that click again, so I used your code u gave
me which worked ok.

But, within the newspaper mc, on the first frame, I wrote a code for a button:
close_btn.onRelease = function () {
gotoAndPlay (2)

}

Didnt work though. I did a trace and that didnt work. I used 'this' at the
beginning of the code and still didnt work. What is going on?
GWD
3/24/2007 10:38:11 PM
Does close_btn exist on the [b]first frame[/b] inside newspaper_mc also? To work this code has to "see" the button on the timeline. If it doesn't exist yet it doesn't get assigned to the button.
Newbie1234
3/24/2007 10:39:47 PM
Newbie1234
3/24/2007 10:45:21 PM
Oh no, I hope u are still there to help. I only just realised, later on within the movieclip, I do need that movieclip to listen out for that 'click' again.

GWD
3/24/2007 10:54:24 PM
Sorry do you mean later on inside the newspaper_mc or later on in your Room_mc?
GWD
3/24/2007 11:02:27 PM
If its later on inside your Room_mc then you can just do the same actionscript
as earlier... newpaper_mc.onRelease = etc.

If it's inside your newspaper_mc then on the frame where you want it to come
back, you can write exactly the same code, but use [b]this[/b] in place of
[b]newspaper_mc[/b]. Hope that makes sense.
Newbie1234
3/25/2007 12:49:59 AM
AddThis Social Bookmark Button