hi, im just starting to learn some action script in flash mx…and im a bit stumped and i was wondering if i could get some help.
I have this bit of code on the movie clip of a bird
Aim - is just a custom cursor i drew
txtStatus - a dynamic text box
my aim was very simple, to duplicate several copies of the movie clip 'Bird" and get the text box to show ‘hit’ when the cursor is over the bird and ‘miss’ when the cursor is anywhere other than over the bird(s).
the thing i’m confused about is ALL the copies of ‘Bird’ respond to the ‘alpha’ change, but only the original* will respond to the change of text. And as for the rotation, i have in the Aim cursor this._rotation += 22.5, so i thought, well, if i minus 22.5 it will make the cursor ‘upright’ (or no rotation), this worked for the copies, but as for the original* it is ‘tilted’ by 22.5 degrees (to the left).
[size=1]**i’m quite sure its the original - even though i placed the original off stage, it still seems to appear when i play the movie.*[/size]
[size=1]
[/size]
i can’t seem to find any errors in my coding/syntax, and what i don’t understand is why the copies respond differently (or don’t respond at all) to each command.
I see the problem. You have 11 birds on your screen, and they all check if they are hit by Aim. If so, then they change the text to Hit, and if not, they change the text to Miss. But if one of them is hit, that one tells to show Hit, but all the others at the same time tell to show Miss. I’ve written an if statement that is a bit more advanced and does the trick.
i’m quite sure its the original - even though i placed the original off stage, it still seems to appear when i play the movie
Sure the orginal appears on stage to… it has the on load random function as well.
But indeed very weird. I don’t think that is a problem of hitTest. But still I’m can’t get to the bottom of this :|.
i understand how the code runs, but just a few syntax queries…
**if (!this.hitTest(this._parent[“Bird”+i])) **
what is the significance of the ‘!’ i this if statment…
this.hitstat ? this._parent.txtStatus.text=“hit!” : this._parent.txtStatus.text=“miss!”;
i don’t quite understand the syntax here…is it a shorthand for an IF statment?
is _parent the same as _root ?
and one last nagging question…when duplicating the mc ‘bird’ is there any advantage in placing the code in the Frame and using:
The ! is a logical NOT. You can read more about it here.
The form
condition ? statement1 : statement2;
is indeed a shortened version of
if(condition){
statement1;
} else {
statement2;
}
I prefer to use this form if only one statement has to be executed if true or false. You can’t use this form with multiple statements. Example: this doesn’t exist:
About _parent and _root - those are a very important aspect of ActionScript, and understanding Flash in general. They have to do with the hierarchical structure of a Flash movie. This structure isn’t the easiest to understand for people who are new to Flash. _parent goes one level up in the hierarchical structure, while _root is the top of the hierarchical structure. There are lots of tutorials out there, and I strongly suggest reading them because this is quite important if you want to get into ActionScript
About the code on the frame - I prefer to do it that way. There are several advantages to this method, not in the least the code standing all together instead of divided to several movieclips here and there. This creates a big advantage, especially when debugging. A second advantage has to do with the scope, but you don’t have to worry about that just yet.
Also, if you’d have placed the duplicating code on the movieclip itself, you’ll create an infinite duplicating loop and crash your Flash movie. That’s because when you place the duplicating code on the movieclip itself and it gets duplicated 10 times for example, then every duplicated movieclip will also execute the code it has and therefore duplicate itself again 10 times. And each duplicate will then again duplicate itself again 10 times. You understand the situation