Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-06-2012, 03:38 AM   #1
NamiOnline
Registered User
 
Join Date: Sep 2011
Posts: 28
Unhappy if statement (rollover)

hi everyone
im just basic in as2 i have problem about if statement .
i want when i rollover a buttom named file alpha = 50 and when rolloverout then alpha = 0 .
is any one can help me

tnx
Code:
 
if (file.onRollOver){
	this._alpha=50;
}else if (file.onRollOut
	this._alpha=0;
}
NamiOnline is offline   Reply With Quote
Old 08-07-2012, 12: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

ActionScript Code:
file.onRollOver = function(){     this._alpha=50; } file.onRollOut = function(){     this._alpha=0; }

Almost, but the idea was great
__________________
I have returned, and am now 18
Prid is offline   Reply With Quote
Old 08-10-2012, 06:37 PM   #3
NamiOnline
Registered User
 
Join Date: Sep 2011
Posts: 28
Default

Tnx for ur answer bro but i want to learn by if statement i will be tnx if u can help me
i want to use file.onRollover inside if condition but it dosen't work

Last edited by NamiOnline; 08-10-2012 at 06:51 PM.
NamiOnline is offline   Reply With Quote
Old 08-12-2012, 12:49 AM   #4
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

Well, first you have to get a better idea of what onRollOver actually is. It's an event handler, meaning that its codes will be executed whenever something happens, in this case, whenever someone rolls over your button/movieclip, while normal functions and if statements (without onEnterFrame) only run once, and then never again. If your function is simply on a Frame, then Flash will only check once for when that happens and then is when you get to that Frame.

What are you using an if statement on anyways? What is the condition of it? Please elaborate
__________________
I have returned, and am now 18
Prid is offline   Reply With Quote
Old 08-12-2012, 04:44 AM   #5
NamiOnline
Registered User
 
Join Date: Sep 2011
Posts: 28
Default

tnx Prid you really useful in this forums OK
im trying make a Photoshop training for my FYP project
i have a file Menu that the menu after clicking , should open ( its pic) after second time click should be close
i used Boolean but seems dosent work :P
the main think that i want is one button do 2 different event


this is my code :P but it just trace number 1 i dont know why can not reach to number 2 :P the first code that i wrote because i just wanted to get the answer from that coding but this is what i really want to do


Code:
 stop();
var click1:Boolean;
click1 = true;
if (click1=true) {
	click1 = false;
	b1.onPress = function() {
	_root.gotoAndStop(10);
	trace("1");

	};

}
if (click1=false) {
	b1.onPress = function() {
	_root.gotoAndStop(20);
	trace("2");
		click1 = true;
	};


}

Last edited by NamiOnline; 08-12-2012 at 04:49 AM.
NamiOnline is offline   Reply With Quote
Old 08-12-2012, 03:41 PM   #6
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

Hi,

first of all, let me explain how the if statement works. So, everything can either be TRUE or FALSE, and an if statement is executed if the condition is TRUE, like, if you check if 5 is equals to 5, then that would be TRUE, meaning that the if statement would execute its codes, but if you checked if 3 was equals to 5, then it'd be FALSE, and the if statement would NOT work. So, if statement works only when the condition is TRUE, even though you may be using a boolean and checking if it's equals to false, because if it is, then that is also TRUE :P

Next thing to keep in mind is the difference between single equal sign and double equal sign:

= sets the left-side variable to the right-side value. Like, click1 = true, then you're setting click1's value as TRUE

== checks if the left-side is equals to the right-side, if they match, and this is how you check if something is TRUE or FALSE

Your mistake was using = in the if statement, rather than ==

But, why did the first if statement, even though you used single equal signs? Because, when you typed if(click1=true), click1's value was first changed to TRUE, and then the if statement checked the value of click1, and since it was TRUE, the if statement was executed. In the second if statement, you first change click1's value to FALSE, and then the if statement checks its value, but since it's then FALSE, the if statement is not executed.

Corrected Code:

Code:
 stop();
var click1:Boolean;
click1 = true;
if (click1==true) {
	click1 = false;
	b1.onPress = function() {
	_root.gotoAndStop(10);
	trace("1");

	};

}
if (click1==false) {
	b1.onPress = function() {
	_root.gotoAndStop(20);
	trace("2");
		click1 = true;
	};


}
That code will probably work, because in the second if statement - if(click1==false) - if click1's value is indeed FALSE, then click1 equals to FALSE will return TRUE, because that condition is TRUE, and then the if statement will work. Same with the first if statement - if(click1==true) - if click1's value is not TRUE (meaning it's FALSE), then click1 is equals to TRUE will return FALSE, because click1 is NOT then equals to TRUE, and thus the if statement will not work.

Hope this helps
__________________
I have returned, and am now 18
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 09:41 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.