BackDoor- Door 1
You find yourself in a strange house with only a man on the phone as a guide.
4.08 / 5.00 27,615 ViewsMini Commando
Action adventure game with nazi enemies in the second world war.
3.91 / 5.00 23,671 ViewsSorry, couldn't resist, had to use AntiPostLimit account, it's ok since it's the original purpose of the anti post limit accounts (like schorhrs)
The one thread to rule them all: AS: Main
This is a useful little thing, again this isn't a long tutorial, it's very basic and it covers a VERY USEFUL OFTEN OVERLOOKED type of looping in flash, the for... in loop
Uses
There are many uses for for in loops:
1)looping over all movieclips in a container
2)looping over all strings on data.
3)looping over all the objects ;)
I will cover:
the instanceof method
for in loops
The actual AS
first of all I'll start with the instance of method, it basically checks if an object is an instance of a class, more advanced talk about classes and objects at AS: OOP.
for example
s.instanceof(String);
will only return true if 's' is a string
_root.mc1.instanceof(MovieClip);
will only return true if 'mc1' is a movieclip
simple eh?
more about instance of
The actual loop
the syntax of a for in loop is:
for(reference in container){
//do actions
}
now the reference part is the one hard to concieve, reference isn't an actual object, it is a reference to all objects. what flash really does is place "links" to all of the objects on the Stage in an array and reference is an array index. more about arrays
the container is the object where the check will be held, for example if _root is the container it will loop over every single thing in your movie, this is why instance of movieclip is importnet
let's look at examples
var counter:Number=0;
for(i in _root){
if(_root[i].instanceof(MovieClip)){
counter++;
}
}
trace(counter);
this counts the number of movieclips in the movie.
remmember container[reference] is always the currently pointed object, in our case _root[i].
very useful, ask any questions
Nice post again,"InglorAntiPostLimit". ; )
very good example I forgot to post ;)
function setFPS(fps:Number):Void{
for(i in _root){
if(_root[i].instanceof(MovieClip)){
_root[i].stop();
}
}
_root.stop();
id=_root.setInterval(function():Void{
_root.nextFrame();
for(i in _root){
if(_root[i].instanceof(MovieClip)){
_root[i].nextFrame;();
}
}
},1000/fps);
return id;
}
this is a very simple dynamic FPS setter using a for in loop
Inglor, I'm on a crappy dial-up computer, and this is the only post I'll make here today, but I'm guessing this could be used to make a pause function in a game? Wait, nvm, I know how I could do this. Good code anyway, I've been wondering how to do this.
yea, you could use it for a pause function, there are better ways though :P
Thanks for covering this type of loop. It was the only one that I wasn't very confident with when I made the AS thread about the others. Your explanation makes a lot more sense than the AS reference dictionary. I understand how to do this stuff now. And yes, the AS thread will rule them all.
linked to the basic loop thread for reference
never knew about the instanceof, thx for that... one thing tho
:: for example
:: s.instanceof(String);
:: will only return true if 's' is a string
:: _root.mc1.instanceof(MovieClip);
:: will only return true if 'mc1' is a movieclip
here your using the syntaqx of object.instanceof(class)
yet, this doesnt work, and according to the link you gave and flashes documentation it should be
object instanceof class
which does work for example
var c:Vector = new Vector(); // im using a class Vector i made to test the instanceof with custom classes
trace(c instanceof Vector);
var s:String = new String();
trace(s instanceof String);
output
true
true
wheras with using object.instanceof(class)
you get the error
Expected a field name after '.' operator.
trace(s.instanceof(String));
SHOOT ME DELTA
godamn it
it's an operator not a method
myClip instanceof MovieClip
what I really ment is:
_root[i] instanceof MovieClip
lol, dont you think youre over exagerating a bit with the SHOOT ME
At 7/23/05 01:15 PM, dELta_Luca wrote: reading your threads makes me want to touch myself, donkey's arouse me.
Thanks I guess... :S
(yeah, I'm recycling the AS varialbes jokes)
sarcasm dude :P
At 7/23/05 01:23 PM, Inglor wrote:At 7/23/05 01:15 PM, dELta_Luca wrote: reading your threads makes me want to touch myself, donkey's arouse me.Thanks I guess... :S
(yeah, I'm recycling the AS varialbes jokes)
sarcasm dude :P
Heh heh I get it
- Matt, Rustyarcade.com
At 7/31/05 09:34 AM, Ninja-Chicken wrote:At 7/23/05 01:23 PM, Inglor wrote:Heh heh I get itAt 7/23/05 01:15 PM, dELta_Luca wrote: reading your threads makes me want to touch myself, donkey's arouse me.Thanks I guess... :S
(yeah, I'm recycling the AS varialbes jokes)
sarcasm dude :P
O_o i dont...enlighten me, please
snyggys
So, you can make a list of all movieclips on stage with:
for(i in _root) {
trace(_root[i]);
}
At 12/19/05 10:15 AM, GameCubeFreak2004 wrote: So, you can make a list of all movieclips on stage with:
for(i in _root) {
trace(_root[i]);
}
No, that will list EVERYTHING.. not just MovieClips.
for(i in _root){
if(_root[i] instanceof MovieClip){
trace(_root[i]._name+" {");
trace("_x: "+_root[i]._x);
trace("_y: "+_root[i]._y);
trace("_xscale: "+_root[i]._xscale);
trace("_yscale: "+_root[i]._yscale);
trace("_width: "+_root[i]._width);
trace("_height: "+_root[i]._height);
trace("_alpha: "+_root[i]._alpha+"\n\n");
}
}
Sup, bitches :)
joke's origin : http://www.newground../topic.php?id=297928
At 12/19/05 10:15 AM, GameCubeFreak2004 wrote: So, you can make a list of all movieclips on stage with:
yes, you can
I have a game where enemies run across the screen. I'm having problems putting them into a loop. Can someone help.
At 3/5/06 03:20 PM, Rookie209 wrote: Can someone help.
Not with that description, no.
Sup, bitches :)
At 3/5/06 03:24 PM, -liam- wrote:At 3/5/06 03:20 PM, Rookie209 wrote: Can someone help.Not with that description, no.
Ok, so far, I have a game where I have a movieclip scroll across the screen towards a tower. If its clicked it dies. I'm having problems putting it into a loop where, overtime a set number of copies of that movieclip will scroll across the screen.
Here is the as I have in the movieclip:
onClipEvent (enterFrame) {
if (_root.Tower._x > _x) {
_x += 5;
}
}
onClipEvent(load){
stop();
}
on(press){
gotoAndStop(2);
}
If i understood what this is about correctly, could this be used to pause a game in flash?
Decima: The Last Story of Vald has a Facebook page and a development blog. Give them a look!
------------------------------
It could be used to loop through all movieclips and their children. It's not a very clever idea of pausing a game, however, that was said when Glaiel was an even bigger noob than now!
At 2/8/07 01:08 PM, OldGust wrote: It could be used to loop through all movieclips and their children. It's not a very clever idea of pausing a game, however, that was said when Glaiel was an even bigger noob than now!
It is clever, just not practical :P
At 2/8/07 01:37 PM, OldGust wrote: How does that go together? >:P
Well frankly I'm impressed that Glaiel could even spell 'pause' at this point :P
But how can something that is not practical be clever? There is no other purpose for it, no?
At 2/8/07 01:40 PM, OldGust wrote: But how can something that is not practical be clever? There is no other purpose for it, no?
If I worked out a way to convert 2000 apples into a banana, that would be clever. Unless there was a serious apple surplus, though, there wouldn't really be any practicality to it.
At 2/8/07 01:41 PM, Paranoia wrote: If I worked out a way to convert 2000 apples into a banana, that would be clever.
Oh, well, yeah. But then it would not be a clever thing to research normally. :P
Unless there was a serious apple surplus, though, there wouldn't really be any practicality to it.
Haha, I doubt it would work out even in our society!
"Daddy, daddy, gemme a fucken banana or I'll fucken bbqpwn your sissy ass! >:C"
At 7/23/05 01:23 PM, Inglor wrote:At 7/23/05 01:15 PM, dELta_Luca wrote: reading your threads makes me want to touch myself, donkey's arouse me.
I hope you use protection.
PS: it's donkeys, not donkey's :P americanub
At 2/8/07 02:30 PM, Toast wrote: I hope you use protection.
PS: it's donkeys, not donkey's :P americanub
wtfbbqhax