Skip to main content
Known Participant
October 27, 2012
Answered

My button stays as "up" when clicked.

  • October 27, 2012
  • 1 reply
  • 1845 views

Hi everyone,

sorry for such a stupid question, but I am experiencing a silly little trouble in my script : I have created a button in my library and changed the value of its saturation in its timeline, under "up" (basically the button is b&w and gets colored when the user mouses over it). When clicked, the whole page (button included) fades out, the button is withdrawn from the stage and a new scene appears.

The problem is that the rest of my website is all in actionscript, and it seems to interfere a bit with this motiontween thing...The button actually works fine, but when I come back to this category of my website, the button appears colored until I mouse on AND mouse over again! So basically the fact that the button fades out seems to block the button from coming back in its original state...Is there a way to solve this issue, possibly by restarting (or updating) the state of a button through actionscript? The weird thing is that my container (which contains the button and another one that has the same problem) gets deleted from the stage at the end of the fade out, and still it reappears in this "up" state.

Anyone has an idea?

Thank you very much in advance.

julien.

This topic has been closed for replies.
Correct answer kglad

Mm...That did not seem to have solve my problem. The adapted script works just as before, which means my button reappears in "up" state when readded to the stage. I might be wrong, but I do not have the feeling that adding the button earlier in the script would change that, since it appears in "up" state and remains like that until I mouse over again. Is there a way maybe to simulate a mouse out when clicking on it? I find always very confusing the relation between the graphic cs5 and the actionscript, but could I not write something like :

function A(e:Event):void {

this.addChild(newButton);

newButton.addEventListener(MouseEvent.CLICK, fadeOut);

}

function fadeOut(e:Event):void {

(...)

newButton.updateState(Up); // I have no idea what would be a right syntax of course.

this.removeChild(newButton);

this.addEventListener(Event.ENTER_FRAME, start);

}

Thank you for your patience and help, I will keep on trying with your script in case I did something wrong.

julien.


you can use:

var newButton:MovieClip

var newButtonOverState:DisplayObject;

if(!newButton){

newButton= new Button();

newButton.addEventListener(MouseEvent.CLICK, fadeOut);

newButtonOverState = newButton.overState;

}

newButton.overState = newButtonOverState;

ButtonA.addEventListener(MouseEvent.CLICK, A); // button leading to the next category.

(...)

function A(e:Event):void {

this.addChild(newButton);

newButton.overState = newButton.upState;

}

function fadeOut(e:Event):void {

(...) // the function makes the objects fade out, "newButton" included.

this.removeChild(newButton); // the button gets removed once faded out.

}

p.s.  please mark helpful/correct responses

1 reply

kglad
Community Expert
Community Expert
October 27, 2012

your button is never undergoing a mouseout.

you can avoid that issue by (re)adding your button to the stage when or before it's re-displayed.

Known Participant
October 28, 2012

Hi,

thanks for your answer. Well, that is what I am doing I think. The button is removed from the stage when you click on it, and is (re)added when you come back into the category. The button is still in up state though.

Known Participant
October 28, 2012

Or actually...my script looks something like that :

var newButton:MovieClip = new Button(); // here is the problematic button, which appears in function A.

(...)

this.addEventListener(Event.ENTER_FRAME, start);

function start(e:Event):void {

this.removeEventListener(Event.ENTER_FRAME, start);

ButtonA.addEventListener(MouseEvent.CLICK, A); // button leading to the next category.

}

function A(e:Event):void {

this.addChild(newButton);

newButton.addEventListener(MouseEvent.CLICK, fadeOut);

}

function fadeOut(e:Event):void {

(...) // the function makes the objects fade out, "newButton" included.

this.removeChild(newButton); // the button gets removed once faded out.

this.addEventListener(Event.ENTER_FRAME, start);

}

Is that the good way I should remove the button? Or should I actually clear the "newButton" variable in order to restart its state?

Thank you very much for your help.

julien.