Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 Basic questions about AS2...

Status
Not open for further replies.

michanagel

Technical User
Jun 23, 2007
34
US
Hi,

my action script skills are (still) very limited and I have two basic questions because I'm kinda stuck here...

1. Is it possible to run an 'if' statement after an 'on release' statement ?

e.g.

on (release){
if (_root.a ==0){
play();
}
}

Every time I try to run code like this nothing happens...

2. I declared a function on frame 1 of my timeline (_root) and I have no problems calling that function and running it as long as the code that calls the function is on the timeline (_root) as well.

But if I try to call the function from within a movieclip that is placed on the timeline, the function won't start...

Do I have to refer to the main timeline to call that function and if so how do I do that ?

e.g.

usually I just call my function with "fadedown();"

I tried "_root.fadedown();" but that doesn't work....

Thanx for your help in advance !

Mike
 
1. Yes! Assuming your condition is ever true...
Always add a trace statement when checking situations like that...

on (release){
trace("Button was pressed!"
if (_root.a == 0){
trace("Condition was met!");
play();
}
}

Of course if the condition isn't met (you don't get the second trace...), the play(); won't occur... Even if the condition is met, nothing may happen, since you're not really saying which timeline you want to play... Now why would the condition not be met? Maybe your _root.a variable hasn't been defined as a number, and if so you should be comparing it to "0" and not 0 as a number...

2. If the function is defined on the main timeline, and you want to call it from a movie clip, then yes you should target it, adding _root to it's path...

Thus using _root.fadedown(); should work...
Again add a trace statement at the beginning of the function to see if the function is at least called, and that if it doesn't do anything, you at least know that the function does get called, but that something else within it, prevents it from doing anything...

function my_function(){
trace("Function called!");
// rest of your code...
};

Regards. FLASH HELP - OPENED FOR BUSINESS!
TO GET YOUR OWN FREE WEBSITE HOSTING
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top