Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-07-2012, 10:19 PM   #1
mrconkin
Registered User
 
Join Date: Jun 2010
Location: British Columbia
Posts: 40
Question Changing a variable with onRollOver

Is it possible to change the value of a variable with an onRollOver function? If not, what would be the best way to go about doing it? The following (simplified) code is located on a frame.

Code:
function onEnterFrame():Void {

	//creates variable with initial value of false
	var fireLit:Boolean = false;
	//for testing
	trace("fireLit is " + fireLit);

	//When mouse rolls over firestart mc I want fireLit to be false, but it's not changing!
	_root.firestart.onRollOver = function() {
		fireLit = true;
	}
}
mrconkin is offline   Reply With Quote
Old 05-08-2012, 08:38 AM   #2
Prid
Prid - Outing
 
Prid's Avatar
 
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,191
Send a message via MSN to Prid Send a message via Skype™ to Prid
Default

Working perfectly here, you're probably doing something wrong. One thing to considerate though, is that using var, you declare a local variable, which means that it will only exist within its own local area, in this case, inside the function, but since you have the onRollOver handler inside the function as well, it shouldn't cause a problem and work

If your function is constantly executed (since it's an onEnterFrame handler), and you want the variable's value to be permanently changed to true, and are only reading the trace() function you've put there, then that's the problem. Each time the function is called, fireLit variable is re-declared, meaning that its value will be reset to false. To prevent this, declare the variable OUTSIDE the onEnterFrame function, so that it's only executed once.
__________________
I have returned, and am now 18

Last edited by Prid; 05-08-2012 at 08:41 AM.
Prid is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:20 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.