Skip to main content
Known Participant
January 18, 2010
Answered

Can AS attach image fade to Toggle button?

  • January 18, 2010
  • 1 reply
  • 1201 views

I have completed my first Flash 8 movie which has an invisible button the size of the image which Stop/starts the movie with AS toggle script below.

click_btn.onRelease=function(){

if(!this.toggle){

chameleon.stop();

} else {

chameleon.play();

}

this.toggle=!this.toggle;

}

Can this script be modified so that the movie fades to alpha zero a short time after the stop action, and the re-appears to play instantly when the play action is triggered? If so can anyone help with a script suggestion please.

This topic has been closed for replies.
Correct answer Ned Murphy

Thanks again Ned,

A freind of my son worked on this question and following your comments came up with the following code but we cannot make it work.

**Error** Scene=Scene 1, layer=Code, frame=1:Line 1: Syntax error.

     import mx.transitions.Tween;

**Error** Scene=Scene 1, layer=Code, frame=1:Line 2: Syntax error.

     import mx.transitions.easing.*;

Total ActionScript Errors: 2 Reported Errors: 2

Can anyone help fix the code please?

import mx.transitions.Tween;

import mx.transitions.easing.*;

var secNum:Number = 2;

var aTween:Tween;

click_btn.onRelease = function() {

if (!this.toggle) {

chameleon.stop();

aTween = new Tween(chameleon, "_alpha", Quad.easeInOut, 100, 0, secNum, true);

aTween.onMotionFinished = function() {

delete aTween;

chameleon._visible = false;

};

} else {

aTween.stop();

chameleon._visible = true;

chameleon._alpha = 100;

chameleon.play()

}

this.toggle = !this.toggle;

};


The code appears to be fine (to me).  Are you sure your Publish Settings are for AS2?

1 reply

Ned Murphy
Legend
January 18, 2010

Look into using the Tween class for the _alpha fade that accompanies the stop();  To have it reappear instantly for the play(); just set its _alpha value to 100 before the play() command.

Known Participant
January 19, 2010

Dear Ned,

Thank you for your suggestion. I am a rank beginner and do not have enough understanding of AS to follow your suggestion. kglad kindly provided the AS cited in reply to an earlier request.

I have looked into AS 2.0 movie clip classes where I can see -alpha. However I cannot find Tween classes and also need to express the -alpha fade time of 10 seconds.

I do not mind doing the research and working at the syntax if you could help me with more specific reference about Tween classes and the expression of time.

Best Wishes,

Ned Murphy
Legend
January 19, 2010

When you use the Tween class it includes a provision for specifying the duration of the transition.  For information on each method and property of the Tween class, look under ActionScript 2.0 Components Language Reference in the Flash help documentation.  The Flash help documents are a primary resource for information on anything to do with actionscript and using Flash.  You can also try searching Google for "AS2 Tween".  Generally Google searches produce excellent results, isolating both the information you might find in the Flash help documents and articles and solutions posted throughout the web.