Skip to main content
Participant
January 27, 2011
Question

Issues with controlling state of boolean variable

  • January 27, 2011
  • 1 reply
  • 470 views

Hi All,

I hope someone can help me out with this cos I'm proper stumped! The really annoying thing is that the code works fine everywhere else, except for when its applied to this one instance.

So basically, I have movie clips on the stage that I have addressed as buttons:

I have three variables set up:

var red_rewind:Boolean; - rewinds hit area animation

var red_txt_rewind:Boolean; - rewinds an explanation animation

var red_info_rewind:Boolean; - rewinds an information panel animation

These functions are initiated in the following code:

// red chairs;
function red_Initial(evt:Event):void
{
    if (red_rewind == true)
    {
        MovieClip(evt.target).prevFrame();
    }
    if (red_txt_rewind == true)
    {
        this.sampson.prevFrame();
    }

       if (red_info_rewind == true)
     {
         this.redInfo.prevFrame();
     }
}

function red_MouseOver(evt:MouseEvent):void
{
    red_rewind = false;
    red_txt_rewind = false;
    red_info_rewind = false;
    MovieClip(evt.target).play();
    Object(this).mc_sweep.gotoAndStop(1);
    this.sampson.play();
    trace(red_info_rewind);
}

function red_MouseOut(evt:MouseEvent):void
{
    red_rewind = true;
    red_txt_rewind = true;
    red_info_rewind = true;
    Object(this).mc_sweep.play();
    trace(red_info_rewind);
}

function red_Select(evt:MouseEvent):void
{
    red_txt_rewind = false;
    Object(this).redInfo.play();
    trace(red_info_rewind);
}

Then I have attached a listener to the relevant object.

mc_red.addEventListener(Event.ENTER_FRAME, red_Initial);
mc_red.addEventListener(MouseEvent.MOUSE_OVER, red_MouseOver);
mc_red.addEventListener(MouseEvent.MOUSE_OUT, red_MouseOut);
mc_red.addEventListener(MouseEvent.MOUSE_UP, red_Select);

For some reason when I call the select function the variable flips from false, to true and then back to false again which causes the animation im trying to play to hitch and stop 1/2 way through.

I have used the exact same script on other objects in the file but with different instance names and they ALL work fine, this is the only one I can't get working. I have tried removing all other scripts to isolate this one but it makes no difference. I am properly stuck!

Hope someone can help,

Regards, Funk247

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
January 27, 2011

you see that variable change when you mouseup repeatedly without moving your mouse?

Funk247Author
Participant
January 28, 2011

Hi, thanks for the reply.

I discovered that the issue was a result of a movie clip (one I was using as

a button)' the mouse and the info panel I was trying to show intersecting on

the stage. Once I moved the info panel away from the mouse the problem no

longer occurred.

At least I can now plan a slight redesign so that the issue no longer

occurs, I presume the info panel appearing under the mouse pointer broke

contact with the button and caused an infinite logic loop.

Is there a simple way to prevent this from happening or will I need to use

transparent buttons on a layer above the info panels?

kglad
Community Expert
Community Expert
January 28, 2011

you can use a loop and hittest to detect mouse events that would otherwise be detected by an object whose mouse events are intercepted by an unrelated object above it.