Skip to main content
Known Participant
February 2, 2013
Answered

Incrementing Counter on Stage through Class

  • February 2, 2013
  • 1 reply
  • 1394 views

Hello everyone, I have a thread similar to this one about saving and loading a counter. However, I can't get the counter to increment when colliding with an object. When colliding with the object, it makes it not visible so you can't see it anymore.

My counter that saves and loads looks like this:

var so:SharedObject = SharedObject.getLocal("myStuff","/");

var JumpCounter: int = 0;

if(so.data.JumpCounter)

{

          JumpCounter = so.data.JumpCounter;

}

And when you jump:

  JumpCounter++;

          so.data.JumpCounter = JumpCounter;

          so.flush();

It ouputs here to a text box:

JumpBox.text = JumpCounter.toString();

This all works fine, I just can't get it to increment when colliding with my MovieClip.

I have a class that looks like this attached to my MovieClip that I want to increment that looks like this:

package {

          import flash.display.*;

          import flash.events.*;

          public class AddJumps extends MovieClip{

                    //construct function

                    public function AddJumps():void

                    {

                              addEventListener(Event.ENTER_FRAME, collision);

                    }

                    private function collision(e:Event):void{

                              if(this.hitTestObject(MovieClip(root).Player)){

                              MovieClip(root).JumpIcon.visible = false;

                              }

                    }

          }

}

I'm unsure as how to access or increment my counter from within a class. I can't seem to remember how to access the stage.

Thanks in advance!

This topic has been closed for replies.
Correct answer kglad

Alright, so I added that to the class and got an error.

ArgumentError: Error #1063: Argument count mismatch on Game_fla::MainTimeline/incrementJumpCounterF(). Expected 1, got 0.

          at CountJumps/collision()

I just need it to add 1 to the counter. Is there an easier way to do that?! You collide with an icon and it increments the counter by one. Thats alllllll


this is the only part you add to your class:

MovieClip(root).incrementJumpCounterF();

1 reply

kglad
Community Expert
Community Expert
February 2, 2013

what are you trying to update, JumpCounter?  so.data.JumpCounter?  something else?

Known Participant
February 2, 2013

Both, technically. I want the counter to increment when I collide with the object that contains the class. I can't seem to remember how to access the stage or something on the stage from within a class.

Known Participant
February 2, 2013

Basically I just want it to add 1 to the counter when it collides. I just don't remember how to access certain things from the stage.