Injecting code and spawning MCs in actionscript 3 - actionscript-3

i'm porting my game from as2 to as3 and i'm stuck trying to figure how to make the enemies work,so on as2 i had enemies as MCs and i had code on then,but now that i'm coding on the main frame time line i don't know how to make many enemies spawn each using the same code.
I tried looking into classes,but still could not make it work.So my question is: how do i spawn many MCs and inject code on them on as3?
help will be much apreciated i'm trying all day long to make it work.

Related

How classes in Adobe Flash Professional works?

I start before 1 year to use CS6 and I found some tutorials that explain how to make pltaformer games, I try a lot of tutorials they work great but for the code they use the timeline.
So, I make a game using the timeline but when I published it and running to my android device I have a lot of lag issues.
After a research I realized that coding in the timeline is a bad idea, also it's better to use Starling for making apps for mobile devices.
So I want to start again to learn how classes working.
I make a new project and I have 5 classes (Main, Level1, Hero, Ground and Enemy). I want the hero to interact with Ground (for gravity) and with Enemy (for hitTest), also Enemy have gravity so they must interact with the Ground.
The concerns are :
In which class I must write the hitTest function?
I have to write in Ground class the hitTest for Hero and the Enemy and in the Hero class to write the collision between the Hero and the Enemy
Or all of this functions must be write in Main class?

Actionscript MovieClip hitTesting

So I am making a side scrolling platform game and I have a number of enemies on my stage. I have made separated classes for my each unique type of enemy. My issue is, in order to do scrolling, I have my player movie clip stay at the centre and have everything else move. I pushed my enemies into arrays by enemy type, I could loop through the arrays and move the enemies one by one. However that would be too much calculations to do on the computer, so I tried putting all my enemies inside one collective enemies movieclip so I can move the single movieclip. My issue is, when i have them out by themselves, they can do the hittest against my platform just fine, when I put them into a movieclip they are not able to detect the platforms. Can anyone tell me why is that so? Any help is greatly appreciated. If anyone need to see my codes please ask.
Thank you!

Box2D world.step() delay at first 2 runs

I'm programming a game using ActionScript 3.0 and included Box2D classes for its physics. It's a maze/labyrinth game having a lot of walls and a ball inside.
In my main fla when I call the maze.create(), the maze is created (visually and physically) and it will dispatch an event so I know when it's done working and then I call my frameHandler which calls another function from my maze class every frame and the big delay accrues exactly at world.step() in it. BUT THE THING IS that it lags only the first two times this function runs!!!
The reason I notice this lag, is that I've got another object starting to move according to mouse position in the same frame handler.
The reason I'm sure the world.step() is causing it, is that everything works fine when I dont call it.
I've seen many codes using Box2d, some had more objects than i have and I know that I've created my b2World and all the objects correctly, similar to all the Box2d tutorials and stuff BUT THEY DONT LAG AT ALL. Its just mine lagging and all!!
Do you have any Idea or similar experience?
Do you have any suggestion in general how to deal with heavy functions?
PLEEEEASE +.-
A maze will have a lot of fixtures in close proximity making a very dense dynamic tree (the method Box2D uses to optimize collision checks). There is unlikely to be any way around this. Perhaps you could just call Step a few times after adding the static walls, but before you add the dynamic ball bodies, and consider it part of the loading process. At least the lagging movements will not be visible to the player.

Action Script 3 - how to pass variables through multiple scenes

I am using flash cs6 and making a game in which some squares are falling down randomly and we have a wall that is controlled by the mouse. Every square we dodge 10 points are added to the score. If the squares touch the wall then we go to another scene called the "the end" scene in this scene we display the score to the player. So I want to pass the score variable to that scene. I have tried googling it a lot of times but it couldn't help. So my only hope is you guys. Please help.
How do I go to the next scene:
if (wall.hitTestObject(square))
{
gotoAndStop(1, "The End");
}
Instead of using flash to create games like this you can Game Maker it is more efficient.
You can go to its website yoyogames.com
Adobe Flash Professional Creative Suit series are for designers, animators. It is one of the worst IDEs for a programmer (notepad would be better). I'd suggest you to get a better IDE like Adobe's Flash Builder which is more suitable for programmers or search for other 3rd party IDEs like IntelliJ Idea which is one of the best from my point of view.
Instead of programming on timeline and using scenes which is for animators, get into the Object Oriented Programming, start with the basics, the classes, then move on with design patterns etc.

Actionscript 3 starling how to drag and only drop if it is over one of many squares

I am making a tower defense game for a class of mine. I decided to use starling with Flash and I am having a bit of trouble. Is there any was for me to specify that the towers can only be dropped into place if they are with in the bounds of a specific image/ in a 100px range of a specified center point? I would want to be able to store the points to be able to reference as I will have about 10-20 spots to place the towers. I feel like I might just be over thinking this.
Any help or guidance would be great.
Maybe you can try the hitTest method and add some dummies for locate the placing. If your hitTest method returns a dummy object you know that you are on a good place.
see Starling DisplayObject:hitTest();