Skip to main content
Inspiring
December 1, 2006
Question

onRelease function - not retuning a number

  • December 1, 2006
  • 2 replies
  • 297 views
Hi,

I'm simply trying to return a variable (number) when the the News button is
pressed.
And then move to frame with a news content, by checking this variable.

The problem is that onRelease is working within the "onRelease function"
scope, but it's not returning the number (vMenuController). This way
"base_mc.gotoAndStop(1);" is not working, too.

base_mc.btnNews.onRelease = function():Number{
trace("function working within it's scope");// Check function
var vMenuController:Number = 1;
return vMenuController;
}

if(vMenuController == 1){//News
trace("moved to frame 1 - News");//Check action
base_mc.gotoAndStop(1);
}


Thanks in advance!
B.


This topic has been closed for replies.

2 replies

December 1, 2006
Hi Bare,

The problem is that you're not scoping your variables correctly. You are creating vMenuController within your onRelease function. Once that function is over, that variable is gone and cannot be used anywhere else. It's generally not a good idea to return a variable from any event function. If you are working from a class-based environment, you could try something like this.

private var vMenuController:Number;

var owner = this;
base_mc.btnNews.onRelease = function():Void{
owner.vMenuController = 1;
}

if (vMenuController == 1){
base_mc.gotoAndStop(1);
}

My main point is that you need to get your variable out of that function's scope and into something larger. Declaring your variable as a root scoped variable would solve the problem (even though it may not be the best programming practice).

Good luck,
Robert
Inspiring
December 1, 2006
Simply pass the mc and the number to a generic function:

base_mc.btnNews.onRelease = function():Void{
var vMenuController:Number = 1;
mcGoToFrame(this._parent,vMenuController);
};

function mcGoToFrame(target_mc:MovieClip,frame:Number):Void{
target_mc.gotoAndPlay(frame);
}
Participating Frequently
December 1, 2006
1. onRelease does not return a value.
http://livedocs.macromedia.com/flash/8/main/00002499.html
2. Place base_mc.gotoAndStop(1); inside of onRelease. Actually you can just place gotoAndStop(1)