Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411530 Posts in 69377 Topics- by 58433 Members - Latest Member: Bohdan_Zoshchenko

April 29, 2024, 02:17:54 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)flash (the ide not the language)
Pages: [1] 2
Print
Author Topic: flash (the ide not the language)  (Read 5194 times)
dustin
Level 6
*


View Profile
« on: August 21, 2008, 12:35:00 AM »

Ok so I recently got my hands on a copy of flash cs3 for cheap.  Anyways I've been fooling around with it and having lots of fun.  It seems very easy to write simple games and I'm not having difficulties with the coding really.  There are some things that I do not understand about the ide and the format in general...

1.  I'm used to inkscape and to me it seems like the flash drawing utilities suck.  When I draw a square I want to be able to select that square as one object (drawing use of the term not programming wise or anything).  In inkscape it's kinda like every shape has it's own layer if you know what I mean but I can't really seem to do that in flash besides physically creating a new layer in flash for every shape I draw.  Is flash meant to do this kinda drawing stuff?

2.  What kinda fps should I be shooting for?  I'm not used to having my stuff running in a browser so my thought is 60 fps but that's obviously too fast for a browser.  So what like 30 or something?  The default 12 seems like it would be to slow, is it?

3.  I'm not really sure where to put my code.  So far I have been just putting it into the first frame.  I just figured out about document class so that solves the problem for the whole project but what about my movie clips.  How do I link code in external files to them.  Also is there any reason besides opinion (does it run faster use less memory etc.) for putting stuff in other files besides just in the frames of the flash project.

And then two general programming questions.

1.  How do I create an array of a specific type of objects.  I can make one but it always is just of ints or strings or something.  I want to say an array of enemies or something so I don't have to cast when taking them out.

2.  Anything that i should avoid that will really slow down my code?

Thanks for all your help guys!
Logged
X-Tender
Level 1
*



View Profile WWW
« Reply #1 on: August 21, 2008, 01:38:43 AM »

1. Flash is not an Illustrator Application, thats why you can draw many stuff in one Layer. Maybe what would be handy for you is the "Draw To Object" Function.
Select your drawing Tool and then the Key "J", or the Icon on the Toolbar with the square with the circle in it. So every time you paint it creates an Object Group.

2. I use 32fps for Brwoser games.

3. when you code with AS3 you put your code in the document class. Check the Thread from Cagey.
Also this tutorial on http://www.gotoandlearn.com.

Programming QUestions:

1.
an AS3 example.
You can push every new created object in an array ..
and then loop through it and execute an function of it.
or do whatever you wnt with it.
Code:
var newEnemy:MyEnemy;
var enemyArray:Array = new Array();
for(var i:uint=0;i<10;i++){
newEnemy = new MyEnemy();
enemyArray.push(newEnemy);
}

var currentEnemy:MyEnemy;
for(var item:String in enemyArray) {
currentEnemy = enemyArray[item];
currentEnemy.doFunctionToMove();
}

2.

a. hundreds of movieclips addet to the stage
b. more then one onEnterFrame event
c. many moving objects with filters/alphas (use BitmapData for such an action)
Logged

Cagey
Level 1
*



View Profile WWW
« Reply #2 on: August 21, 2008, 03:11:43 AM »

The biggest reason for not using the Flash CS3 IDE for coding is because it lags like a bitch when the code gets slightly bigger than absurdly short. If you're on windows, FlashDevelop has amazing code completion and integrates very nicely with the Flash IDE. The coolest thing is being able to click build inside FlashDevelop, and seeing it open up the Flash IDE and compile it within the IDE.

Flash is meant for vector graphics, but because it is designed to be dynamic, things work a little differently to what you may be used to. Flash was originally appearance first, code second but now things are more balanced.

For finding a suitable framerate, 24 seems to be the lowest standard framerate amoungst flash video and game creators. I use 30.

If you are using Actionscript 3.0 (which you most certainly should be using. AS2 is way behind the times) this is superb. It's an entity framework for holding a bunch of objects. I ended up making heaps of tweaks to it to suit what i was after, so if you want some tips please ask.

Finally, arrays can't be of fixed types, and the only unobvious thing that i can think of that slows flash down is excess function calls. For some reason they are rather CPU expensive, though in all honesty you shouldn't worry about optimisation until you need to. It's hard enough to create a laggy game, and once you get that (if you get that) then you can optimise.
Logged

Gnarf
Guest
« Reply #3 on: August 21, 2008, 03:18:57 AM »

1.  I'm used to inkscape and to me it seems like the flash drawing utilities suck.  When I draw a square I want to be able to select that square as one object (drawing use of the term not programming wise or anything).  In inkscape it's kinda like every shape has it's own layer if you know what I mean but I can't really seem to do that in flash besides physically creating a new layer in flash for every shape I draw.  Is flash meant to do this kinda drawing stuff?
Heh, for much the same reasons I find Flash to be a lot more convenient and intuitive. Easily being able to draw lines all over each other and then click and delete the bits of line I no longer need is nice. With stuff like the tail of the creature in my avatar, I find drawing a couple of lines from the circle-thing that is its body preferable to making a new shape and positioning it and combining it with the body-shape. I'm sure it's not a terribly convincing example, but with my style of drawing things it just seems like the things I do all the time are a lot more straightforward to do in Flash. With Inkscape and various other vectory programs it feels like I'm doing vector-work with shapes, altering vertex positions and such, while with Flash it just sort of feels like drawing things.

I'm sure it matters rather a bit that I'm a lot more familiar with Flash and that it was really the first vector drawing thing I got my hands on (not horribly surprising that Flash is pretty good for a style I've developed while using Flash), and odds are it just comes down to preference. Doesn't really suck though Smiley

And like what I think X-Tender said, you can create objects out of whatever while you're drawing things. Just doesn't happen automatically when you make a circle or something.
Logged
bateleur
Level 10
*****



View Profile
« Reply #4 on: August 21, 2008, 04:17:51 AM »

1.  How do I create an array of a specific type of objects.  I can make one but it always is just of ints or strings or something.

An Array is untyped (not ints or strings!).

If you want a typed thing that behaves like an Array you'll need to write your own object class. But not from scratch necessarily, just as a thin wrapper around Array. So you end up with something like...

Code:
public class FooArray {
 var elements:Array;

 public function read(index:Number):Foo {
  return(Foo(elements[index]);
 }

 public function write(index:Number,foo:Foo) {
  elements[index] = foo;
 }
}

...and you can add push() and pop() and insert() and whatever else you want in the obvious way.
Logged

muku
Level 10
*****


View Profile
« Reply #5 on: August 21, 2008, 04:21:26 AM »

Or use haXe. It has properly typed arrays and is the superior language all around.
Logged
dustin
Level 6
*


View Profile
« Reply #6 on: August 21, 2008, 09:35:50 AM »

Quote
3. when you code with AS3 you put your code in the document class. Check the Thread from Cagey.
Also this tutorial on http://www.gotoandlearn.com.

OK I think I phrased my question wrong.  Because of reading that thread I understand how to move stuff out of my first frame of the movie using document class.  What I still don't understand is how to not put code inside the frames of my movie clips.  How do I link the code to the movie clips in flash.


Quote
1. Flash is not an Illustrator Application, thats why you can draw many stuff in one Layer. Maybe what would be handy for you is the "Draw To Object" Function.
Select your drawing Tool and then the Key "J", or the Icon on the Toolbar with the square with the circle in it. So every time you paint it creates an Object Group.
Ok I'll try that.

Quote
a. hundreds of movieclips addet to the stage
b. more then one onEnterFrame event
c. many moving objects with filters/alphas (use BitmapData for such an action)

cool thanks those first two where both things i was planning on doing but I know how to get around them.

Quote
The biggest reason for not using the Flash CS3 IDE for coding is because it lags like a bitch when the code gets slightly bigger than absurdly short.

Do you mean when coding a lot the ide lags or when you code a lot in the actual frames the movie will lag a lot?

Quote
Finally, arrays can't be of fixed types, and the only unobvious thing that i can think of that slows flash down is excess function calls. For some reason they are rather CPU expensive, though in all honesty you shouldn't worry about optimisation until you need to. It's hard enough to create a laggy game, and once you get that (if you get that) then you can optimise.

Ok cool I'm fine with arrays not being fixed types as long as it means I don't have to cast everything when i take it out.

Quote
Heh, for much the same reasons I find Flash to be a lot more convenient and intuitive. Easily being able to draw lines all over each other and then click and delete the bits of line I no longer need is nice.
Yeah I think it's more the fact that I'm not a good artist at all that makes me not like the flash interface.  I can handle inkscape because I just have to lay down circles and squares and deform them a bit.  I never really use the actual pen tool in inkscape.  So yeah... that's probably why.

Quote
An Array is untyped (not ints or strings!).
ok cool I just always saw people putting what I guess you would call primitives in them  in all the tutorials so I didn't know you could stick in anything.

Quote
Or use haXe. It has properly typed arrays and is the superior language all around.

haXe looks pretty crazy but I'll probably stick to learning flash first.

Thanks everyone for all the help!
Logged
X-Tender
Level 1
*



View Profile WWW
« Reply #7 on: August 22, 2008, 12:39:44 AM »

Quote
OK I think I phrased my question wrong.  Because of reading that thread I understand how to move stuff out of my first frame of the movie using document class.  What I still don't understand is how to not put code inside the frames of my movie clips.  How do I link the code to the movie clips in flash.
Hm, why would you like to do that?
I mean you can wirte with AS3 code to the timeline .. but I would like to know an example where you would like to do that?!


Quote
cool thanks those first two where both things i was planning on doing but I know how to get around them.
I usealy do somethign like that

Code:
private function mainloop():void {
getInput();
movePlayer();
moveEnemys();
renderWorld();
renderPlayer();
renderEnemys();
//ect.
}

Quote
Do you mean when coding a lot the ide lags or when you code a lot in the actual frames the movie will lag a lot?
I think he mean the coding env. of FLash, I also use FlashDevelop <3
Logged

dustin
Level 6
*


View Profile
« Reply #8 on: August 22, 2008, 02:38:50 PM »

Quote
Hm, why would you like to do that?
I mean you can wirte with AS3 code to the timeline .. but I would like to know an example where you would like to do that?!
no I meant the oppisite of that but it's ok I figured it out.  You just have to name the class the same thing.

Quote
Finally, arrays can't be of fixed types, and the only unobvious thing that i can think of that slows flash down is excess function calls. For some reason they are rather CPU expensive, though in all honesty you shouldn't worry about optimisation until you need to. It's hard enough to create a laggy game, and once you get that (if you get that) then you can optimise.

well you see there is the problem I'm having.  Right now I have the player, 1 non moving block, 1 zombie, and 2 bullets max on the screen right now.  Whenever I fire off even 1 bullet the game drops from 30fps to 20 fps.  Same thing happens if I add 1 more zombie and don't fire any bullets.  It's like whenever I add more then 1 or 2 moving objects on the screen the framerate drops by like 10.  That's not normal is it?  I'm moving the objects around by just saying x+=velx; and y+=vely; that's how I'm supposed to do it right?  Anyone know what that might possibly be.  At first I thought it was the collision detection but turning that off doesn't change anything.  It's weird...  I'm adding these images just to the stage is this bad?  Should I just have 1 sprite that I call actors or something add that to the main and then add all my sprites there?
Logged
bateleur
Level 10
*****



View Profile
« Reply #9 on: August 23, 2008, 01:35:17 AM »

It's like whenever I add more then 1 or 2 moving objects on the screen the framerate drops by like 10.  That's not normal is it?

Indeed not. Sounds like you have a major bug.

Quote
I'm moving the objects around by just saying x+=velx; and y+=vely; that's how I'm supposed to do it right?

That's fine, yes.

The kind of slowdown you're seeing won't be some sort of minor issue like that. You must be doing something like running 100 copies of your game at once or some similarly ridiculous problem. I've had Flash running at 50fps with 100 objects on screen with no difficulty (and my machine's not insanely powerful).
Logged

X-Tender
Level 1
*



View Profile WWW
« Reply #10 on: August 23, 2008, 08:39:36 AM »

Sounds crazy, maybe show us the source :D
Logged

dustin
Level 6
*


View Profile
« Reply #11 on: August 23, 2008, 09:17:22 AM »

Ok then I must be doing something way wrong... Here is the source with as much stuff taken out so as to replicate the problem...

Code:
package {
import flash.display.*;
import flash.events.*;
import flash.utils.Timer;
import flash.text.TextField;

public class ZombieGame extends MovieClip {
var zombies:Array = new Array();
var blocks:Array = new Array();
var pickups:Array = new Array();

var zombieTimer:Timer;
var player:Player;
var timer:Timer;
var frames:int;

var blood:Sprite;


public function ZombieGame():void {
init();
}


function init():void{
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
stage.addEventListener(Event.ENTER_FRAME, update);

player=new Player();
player.x=100; player.y=100;
addChild(player);

var i:int;
for(i=0;i<8;i++){
var zombie:Zombie = new Zombie(player,blood);
zombies.push(zombie);
addChild(zombie);
}



timer=new Timer(1000);
timer.addEventListener(TimerEvent.TIMER,fps);
timer.start();


}


function fps(TimerEvent){
fpsOut.text="frames: "+frames;
frames=0;
}

function keyPressed(key:KeyboardEvent){
player.controls(key.keyCode);
}

function keyReleased(key:KeyboardEvent){
player.released(key.keyCode);
}

function update(called:Event){
frames++;



var i:int;
var j:int;
player.update(called);
for(i=0;i<zombies.length;i++){
zombies[i].update(called);
}

}


}
}

That is the Document class or whatever.  And now here is the zombie class...

Code:
package {
import flash.display.Sprite;
import flash.events.*;
import flash.events.Event;

public class Zombie extends Actor {
var player:Player;
var blood:Sprite;
var respawn:int;

function Zombie(aplayer:Player, ablood:Sprite){
player=aplayer;
blood=ablood;
die();
}

function update(Event):void{
respawn--;
if(respawn==0)visible=true;
if(respawn<0){
velx = (Math.random()*5)-3;
vely = (Math.random()*5)-3;

if(player.x<x)velx--;
if(player.x>x)velx++;
if(player.y<y)vely--;
if(player.y>y)vely++;

x+=velx;
y+=vely;
}
}

function die():void{
var side:int;
side=(Math.random()*100)%4;
switch(side){
case 0: x=-50; y=Math.random()*400; break;
case 1: x=600; y=Math.random()*400; break;
case 2: x=Math.random()*550; y=-50; break;
case 3: x=Math.random()*550; y=450; break;

}

respawn = Math.random()*180+30;
visible=false;

}
}
}

and finally here is the player...
Code:
package {
import flash.display.Sprite;
import flash.events.*;
import flash.events.Event;

public class Player extends Actor {
var speed:int;
var gun:Gun;

public function Player():void {
init();
}


function init():void {
speed=10;
}

function update(called:Event):void {
x+=velx;
y+=vely;
}

function controls(keyCode:int):void {

if (keyCode==38) {//up
vely=speed*-1;
} else if (keyCode==40) {//down
vely=speed;
} else if (keyCode==37) {//left
velx=speed*-1;
} else if (keyCode==39) {//right
velx=speed;
}

}

function released(keyCode:int):void {
if (keyCode==38) {//up
if(vely==speed*-1)vely=0;
} else if (keyCode==40) {//down
if(vely==speed)vely=0;
} else if (keyCode==37) {//left
if(velx==speed*-1)velx=0;
} else if (keyCode==39) {//right
if(velx==speed)velx=0;
}
}
}


}

What happens is everything is going fine before the zombies come on screen... Running at a nice 30 fps.  Then as soon as a couple appear the fps drops to a steady 21 fps from it's 30 and never goes back up again unless all the zombies stack on top of each other...

I really appreciate all the help guys!

Also if the number of zombies is 8 or 30 the fps still drops to a steady 21 and then doesn't change.  Also no matter what the starting fps it still drops to 21.  This is of course all tested by me pressing command return.  I don't know if there is a different way your supposed to do these things...
« Last Edit: August 23, 2008, 09:22:28 AM by dustin » Logged
X-Tender
Level 1
*



View Profile WWW
« Reply #12 on: August 23, 2008, 10:11:16 AM »

1. "Actor" is a MC in your Library=

2. why did you pass over the event from the main update function to the zombie and player update function?

3. also .. why are your class functions not public or private?! functions that you call from outside of the class needs to be public, otherwise make it private.
Specialy the zombie class, the constructor

4. constructor functions doesnd have to het an return value (in your vase the :void)
Logged

dustin
Level 6
*


View Profile
« Reply #13 on: August 23, 2008, 10:16:23 AM »

Oh right sorry about that actor is just this...


Code:
package {
import flash.display.Sprite;
import flash.events.*;
import flash.events.Event;

public class Actor extends Sprite {
var velx:int;
var vely:int;
}
}

Its not important for the part I have in there just for another part I coded involving platforms...

2.  I originally wrote the update functions as each having there own on frame load event listener but then I took the individual ones out and put them all into the one main update function but figured I should still pass the event around.

3.  Sorry bad habit from C I guess

4.  Oh right it still seems to compile fine though
Logged
X-Tender
Level 1
*



View Profile WWW
« Reply #14 on: August 23, 2008, 11:22:55 AM »

well, so far i cant see andy stuff that would cause that frame drop. in you want you could send me your fla/as files .. or ICQ or whatever Smiley

/e:
Ok I just crreated the 4 classes and an Object in my Library called "Actor" of thye Sprite ..

and it works perfectly here (with also 100 zombies)
« Last Edit: August 23, 2008, 11:36:41 AM by X-Tender » Logged

Cagey
Level 1
*



View Profile WWW
« Reply #15 on: August 23, 2008, 04:25:10 PM »

Code:
		function released(keyCode:int):void {
if (keyCode==38) {//up
if(vely==speed*-1)vely=0;
} else if (keyCode==40) {//down
if(vely==speed)vely=0;
} else if (keyCode==37) {//left
if(velx==speed*-1)velx=0;
} else if (keyCode==39) {//right
if(velx==speed)velx=0;
}
}

Instead of saying if (keyCode==39), you can import flash.ui.Keyboard, and say if (keyCode==Keyboard.UP). You can read more about it on the Keyboard AS3 livedocs page.

Looking forward to seeing the final product.
Logged

dustin
Level 6
*


View Profile
« Reply #16 on: August 23, 2008, 05:20:59 PM »

OK I'll upload the whole thing when I get back to my house.  I'll also try running it on another computer.  Maybe that's it.

Quote
Instead of saying if (keyCode==39), you can import flash.ui.Keyboard, and say if (keyCode==Keyboard.UP). You can read more about it on the Keyboard AS3 livedocs page.

Ahh sweet I was wondering how to do that.  Thanks for the tip. 
Logged
dustin
Level 6
*


View Profile
« Reply #17 on: August 23, 2008, 11:11:14 PM »

OK I sent the PM.  In case anyone else wants to try to help here are the flash files...

http://nitsud.rhodes.googlepages.com/test.zip

I took out all the code I could and still have the problem appear.  What happens is after 5 or so zombies the fps drops from 30 to 21 and stays there bassically no matter how many more I create.  Thanks everyone!
Logged
dustin
Level 6
*


View Profile
« Reply #18 on: August 23, 2008, 11:44:26 PM »

Ok now that I have that done I tried running it under a ton of different ways and  I have found that running it by double clicking the html file (in other words running it not from the flash ide) runs at 30 fps while inside the ide publish previewing to html drops to 25 with zombies and publish previewing as a movie drops to 21 fps after a couple zombies come on.  I guess that means there's no problem with my code?  I'd still like to know what in the world is up with that though if anyone has any ideas...
Logged
isaac
Level 2
**



View Profile WWW
« Reply #19 on: August 24, 2008, 12:51:10 AM »

Yeh, your code looks fine... though I'm not sure why you're sending the timerevent to the Zombie.update()?

I've found that the debug player in the Flash IDE lags out much, much earlier than the same code running in the standalone or browser players. Unless you're doing something really weird or fancy, you can generally get <100 sprites running just fine in AS3.
Logged

Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic