all groups > flash actionscript > may 2006 >
You're in the

flash actionscript

group:

Help with this code, please?


Re: Help with this code, please? DMennenoh **AdobeCommunityExpert**
5/20/2006 11:56:22 AM
flash actionscript:
[quoted text, click to view]

Right... your code is a bit messed up.

You can't define function b1release() inside of the button's onRelease...
that is just not going to work. I'm not exactly sure what you're trying to
do here, but something like this is more appropriate:

Button1.onRelease = b1Release;
b1Release = function(){
var my_valid_frames:Array = new Array(2,4,6);
var temp_frame:Number = my_valid_frames[random(my_valid_frames.length)]
this.gotoAndPlay(temp_frame);
}



--
Dave -
Adobe Community Expert
www.blurredistinction.com
www.macromedia.com/support/forums/team_macromedia/

Help with this code, please? Angyl
5/20/2006 4:34:38 PM
I've had this code working before in other projects, but for some reason it's
not working now in this new one. Can anyone see the problem?

There's a "Button1" instance on the stage and the Actionscript for the frame
has this:

Button1.onRelease = b1release() {
var my_valid_frames:Array = new Array(2,4,6);

function b1release() {
var temp_frame:Number = my_valid_frames[random(my_valid_frames.length)]
this.gotoAndPlay(temp_frame);
}


When you press the button, absolutely nothing happens.
Re: Help with this code, please? blemmo
5/20/2006 4:47:46 PM
I doubt that this code ever worked. You're mixing 2 things up here:

Button1.onRelease = function() {
var my_valid_frames:Array = new Array(2,4,6);
}

This the 'inline' function way, you create a (nameless) function 'on the fly'
and define it right away.
And then there's

Button1.onRelease = b1release;
function b1release() {
var temp_frame:Number = my_valid_frames[random(my_valid_frames.length)]
this.gotoAndPlay(temp_frame);
}

where a named function is assigned to onRelease, which is defined seperately.
Note that there are no brackets ( ) in the assignment.

Both ways are fine, but not at the same time.

hth,
blemmo
AddThis Social Bookmark Button