Copy link to clipboard
Copied
Hello
I have 4 objects inside movie clip each one with code on it's the 2nd frame tile.visible = false;. To refer to that frame 2 from the main timeline I have "cont.tile1.addEventListener(MouseEvent.CLICK, fr2); function fr2(event:MouseEvent):void { tile1.gotoAndStop(2); }" This code 1 time for each tile(renamed). The objects( tiles) are inside mc called "cont". Once they are all clicked and are invisible I need to take action like for example to go to frame 5 on the main timeline.How can i make that possible?. Thanks.
Keep track of how many you click in the main timeline and when all are clicked just issue the command.
You could use one function instead of having a function for each tile....
var clickedCount:int = 0;
function f(event:MouseEvent):void {
MovieClip(event.currentTarget).gotoAndStop(2);
clickedCount ++;
if(clickedCount == 4){
gotoAndStop(5);
}
}
Copy link to clipboard
Copied
Keep track of how many you click in the main timeline and when all are clicked just issue the command.
You could use one function instead of having a function for each tile....
var clickedCount:int = 0;
function f(event:MouseEvent):void {
MovieClip(event.currentTarget).gotoAndStop(2);
clickedCount ++;
if(clickedCount == 4){
gotoAndStop(5);
}
}
Copy link to clipboard
Copied
Thank you for your answer
My knowledge limitations are not allowing me such luxuries as to write 1 code instead of 4, I don't understand how do you refer inside the tile mc inside the container. There are 4 tiles each one with separate instance name. If you can just tell me how to go to frame 5 in the given configuration would be great. :Newtest.fla - Box.
Copy link to clipboard
Copied
The code I provided already does that. You just need to add event listeners like you already did, changing them to call the function "f" that I showed instead of the function(s) you have.
Copy link to clipboard
Copied
Thank you very much I figured it out.
Copy link to clipboard
Copied
You're welcome
Copy link to clipboard
Copied
Is there anyway you can tell me how would the code look for collision event (not mouse) This is what I have so far. This code is inside the container
mc.
tile1.addEventListener( Event.ENTER_FRAME, handleCollision)
function handleCollision( e:Event ):void
{
if(tile1.hitTestObject(MovieClip(parent).mcball))
MovieClip(event.currentTarget).gotoAndStop(2);
clickedCount ++;
if(clickedCount == 4){
gotoAndStop(5);
}
Is this about right?
How would I tell it when a collision event happens with mcball located on the main timeline to go to frame 5 also on the main timeline.
Copy link to clipboard
Copied
MovieClip(parent).gotoAndStop(5);
Copy link to clipboard
Copied
Thank you! It doesn't work though... I get an error if undefined property on "event" on the underlined line. Maybe there is a problem in clarifying that the current target is tile 1?
function handleCollision( e:Event ):void
{
if(tile1.hitTestObject(MovieClip(parent).mcball))
MovieClip(event.currentTarget).gotoAndStop(2);
hitCount ++;
if(hitCount == 4){
MovieClip(parent).gotoAndStop(5);
}
}
Copy link to clipboard
Copied
That's because you changed "event" to just be "e"... you need to change it anywhere it is used in that function.
Copy link to clipboard
Copied
Thank you! that's right.
Now there is a problem with this line:
if(tile1.hitTestObject(MovieClip(parent).mcball))
Parameter hittestobject must be non null
It's fine with the syntax, what are they talking about?
Copy link to clipboard
Copied
It does not work in any configuration, I also tried this:
if(tile1.hitTestObject.(root["mcBall"]))
MovieClip(e.currentTarget).gotoAndStop(2);
#1123: Filter operator not supported on type builtin.as$0.MethodClosure.
I am sorry if I am being too annoying to ask, but it's my dream to achieve this.
Copy link to clipboard
Copied
In your hitTest line you have a period where there should not be one. That is what is giving you the 1123 error
if(tile1.hitTestObject. <- remove that period
Copy link to clipboard
Copied
Thank you for answering.
I really need to see somewhere a working example of calling instance name from inside movie clip.
if(tile1.hitTestObject(MovieClip(parent)mcBall)) That line is not working,
1084: Syntax error: expecting rightparen before mcBall.
(When I put right paren Is still saying the same along with other errors).
Also when I try: if(tile1.hitTestObject(root["mcBall"])) without the dot as you mentioned
1009:Cannot access property of null object reference.
In both ways would not work.
Copy link to clipboard
Copied
MovieClip(parent).mcBall <- you are missing the dot in this line
Copy link to clipboard
Copied
Thanks! It is still not recognizing the mcBall on the main timeline for some reason.
Error #1009: Cannot access a property or method of a null object reference
I'll keep posting new questions and hopefully will go to frame 5 before christmas.
Copy link to clipboard
Copied
You should try keeping all of your code in the main timeline so that you are always referencing thru child objects rather than trying to target parent objects
Copy link to clipboard
Copied
It's for a breakout game and the mc holding the tiles will be a level, so it's easier configuration.....at least for me. I tried putting these lines on the main timeline still to try if it's going to work. It was giving me errors on the code that is already there. So it was very confusing. Anyway... thanks.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now