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

Action when mc is empty

Guest
Sep 28, 2014 Sep 28, 2014

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.

TOPICS
ActionScript
1.2K
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 , Sep 28, 2014 Sep 28, 2014

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);

     }

}

Translate
LEGEND ,
Sep 28, 2014 Sep 28, 2014

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);

     }

}

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
Guest
Sep 30, 2014 Sep 30, 2014

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.

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 ,
Sep 30, 2014 Sep 30, 2014

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.

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
Guest
Sep 30, 2014 Sep 30, 2014

Thank you very much I figured it out.

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 ,
Sep 30, 2014 Sep 30, 2014

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
Guest
Sep 30, 2014 Sep 30, 2014

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.

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 ,
Sep 30, 2014 Sep 30, 2014

MovieClip(parent).gotoAndStop(5);

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
Guest
Oct 01, 2014 Oct 01, 2014

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);

     }

}

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 ,
Oct 01, 2014 Oct 01, 2014

That's because you changed "event" to just be "e"...  you need to change it anywhere it is used in that function.

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
Guest
Oct 01, 2014 Oct 01, 2014

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?

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
Guest
Oct 02, 2014 Oct 02, 2014

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.

Break3.fla - Box

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 ,
Oct 03, 2014 Oct 03, 2014

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

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
Guest
Oct 06, 2014 Oct 06, 2014

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).

Break2.fla - Box

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.

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 ,
Oct 06, 2014 Oct 06, 2014

MovieClip(parent).mcBall    <- you are missing the dot in this line

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
Guest
Oct 07, 2014 Oct 07, 2014

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.

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 ,
Oct 07, 2014 Oct 07, 2014

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

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
Guest
Oct 07, 2014 Oct 07, 2014
LATEST

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.

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