Action Script 3 - how to pass variables through multiple scenes - actionscript-3

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.

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?

Understanding AS3 parent/child relationships

I've looked around the site, but as a beginner, the AS3 lingo is a bit beyond me. I know that parent/child is used to pass information, commands, and variables between scenes and movie clips embedded in each other, but I don't quite understand HOW or WHY it works.
When I say beginner, I mean it. This is my first flash project. In case it helps, this is what I'm trying to do:
I'm making a type effectiveness calculator for Pokemon. I've successfully made 3 movie clip "dials" that will cycle through the different Pokemon Types when buttons on them are pressed. 18 Types, 18 frames per "dial". 19 frames on the third "dial", for a blank type.
I've also made a 4th movie clip that will display the effectiveness, from 0.25x up to 4x.
So, basically, I need to...
1) Pull either a numerical variable (or frame number) up from each of the "dials"
2) Calculate the effectiveness based on those numbers in Scene 1 (or a new, all-inclusive movie clip if that's easier)
3) Then send the result (or desired frame number) down to the 4th movie clip to display the effectiveness.
Aaaaaaaand I have zero clue how to do that. I'd appreciate an explanation as opposed to just telling me how. I WANT to understand.
Thanks in advance, everyone!
You are wanting to understand Object Oriented Programming. Specifically the concept of "containers". Google "AS3 OOP containers tutorial" and you'll find what you need.

Working with Graphics in Actionscript

i haven't worked with graphics until now.. so I have not much ideas about using graphics objects in flash cs6.
I want to move this character depending if the person has pressed a button and stop his movement once the button is released. I looked up on how to go about this process.. so far one thing that kept coming up was to turn my spritesheet into graphics.. but after that i couldn't really find anything on how to integrate this into actionscript. Plus when I convert an object into graphics it doesn't give me options to assign it a class name. so can somebody give me a good breakdown on what is the purpose of these graphics objects? and how should I go about making a sprite move?
Disregard information concerning sprite sheets. These are used as a completely different method of graphics rendering that I'm not going to cover here; for more advanced, high performance applications and games.
When you say Graphics, I am assuming that you mean you've created some drawings that you've converted to a Graphic like this:
These types of objects are used purely for timeline animation. What you want to use here is the type MovieClip. When you use this type, you'll be able to give the object a class name like you mentioned:
After doing this, you'll be able to refer to that library symbol in ActionScript like this:
var gr:MyGraphic = new MyGraphic();
addChild(gr);

(AS3) Does setting variables to private help garbage collection?

Novice programmer here.
I'm currently coding a simple game with the title screen and the main game loop in separate "keyframes" (this is in CS6). Once I transition from the title screen to the game keyframe I'm concerned that the buttons/movieclips/variables are going to stick around and waste memory + clutter the screen.
If I have the variables/functions set to "private" will that help the garbage collector take care of them? How should I go about "clearing the screen" and making sure I'm not being wasteful/leaking memory?
None of the tutorials or books I've been reading to learn AS3 have really covered this topic, if there are any good guides or obvious tips I've missed as far as memory management best practice goes in AS3 I'm interested in seeing them. The only thing I've learned so far is that I should manually set all my event listeners to weak reference.
Bonus question: I'm using a full-screen bitmap and blitting things onto it for my display. If I am blitting dozens of objects onto the screen per frame I don't need to worry about the blitted "sprites" that are being "covered up," do I? I'm hoping that the bitmap is one pixel thick and not just stacking things on top of each other.
Firstly, the only way you will have total control over your resources is if you leave the timeline for what it was intended for, creating and exporting assets in to swc or swf format, which you can embed the former and either embed or load the latter.
What you should be doing is learning how to develop in an Object Oriented manner, starting with a Document class (as you're using CS6) and then building your game using a series of classes which have defined tasks. Using classes promotes re-usability throughout your game. Depending on the complexity, I would consider a framework like PureMVC or Robot legs.
Garbage collection in flash is mark and sweep, which means you have to de-reference all your objects, which usually starts with removing associated listeners, timers and any further references to them, eg. clearing from arrays or objects hashes. Finally you would set the object in question to null which makes it 'elligible' for garbage collection but does not actually guarantee it. Flash will come and clean up as it sees fit.
Personally if you could get hold of Flash Builder, this has a fantastic memory management profiling tool, when you are developing using OOP mentioned above, you can use this tool to see all the instances that exist in your game. Now the good part here is you can do a memory snapshots in time, and compare them to see which objects linger around and are causing memory leaks. There is a garbage collection button which you should invoke between capturing snapshots, this is only available as you are developing, though using Adobe AIR you can force gc calls manually.
Regarding your bonus question, im not sure how you are doing this blitting, if you are adding objects to the stage this is increasing memory, you cannot avoid this. What you describe as 1px thick is what flash renders, you can see what is being redrawn by right clicking on the stage and selecting the redraw regions option, to see a red box showing what flash has to redraw, it will only redraw what it needs to, this is useful to check if your frame rate suffers.
So to summarize:
Consider using Flash CS6 for creating assets.
Learn about Object Oriented programming in Actionscript 3.
Consider developing in Flash Builder (or free Flash Develop).
OOP will help with organisation and de-referencing objects for garbage collection.
I hope this helps and good luck with your game.

Flash side scrolling game theory

AS3.0 newbie here.
My goal: To create a side-scrolling motocross game (horizontal - already have terms on side scrolling methodology).
The bike - should react to jumps, etc.
Wheels need to turn when gas is pressed, etc (is this a basic animation on keyboard events, or is it actually what 'drives' the machine??)
The rider - should hang on to bike, lean forward, backward, etc.
My question lies within where should be the best place to start? I know this isn't going to happen over night, and my primary focus is on the bike & suspension & rider physics (making sure the suspension/bike/rider react correctly to bumps).
The end result (someday) will be something similar to:
http://www.youtube.com/watch?v=mpR0wbE_6Qs
Kind of an abstract question, but any help is greatly appreciated.
Thank you
There are a handful of resources for Flash game development out there,
http://www.seinia.com/ teaches some useful basics.
Adobe has a good list of some engines as well: http://www.adobe.com/devnet/games/gaming_engines.html
I would definitely check out Box2D and Fixel as they are pretty slick.
There is a similar topic with a few good suggestions for side scrolling physics games: Scrolling the 2d world with physics