New to AS3, adrift on simple concept
I'm trying to do a basic little project as a way of teaching myself as3, and I can't even get off the ground. The goal is to have two scenes, each with their own backgrounds and descriptions, that the user can go between. Step one of that is to be able to tell the game which background to load, and I can't even get that far.
Here's what I have:
There's nothing to it at this point. It loads with a start button, whuch when clicked is supposed to load the appropriate BG. However, I'm having a hard time getting the names of the BGs out of the array where they're stored (It works fine when hard-coded). I suspect I'm using getDefinitionByName wrong. Can anyone help? I
var curScene:int = new int(1);
var sceneData:Array = new Array("BG_Day", "BG_Night");
startButton.alpha = 0;
startButton.enabled = false;
startButton.alpha += 0.05;
if(startButton.alpha >= 1)
startButton.enabled = true;
var startRaise:Tween = new Tween(startButton, "y", Regular.easeIn, startButton.y, -100, 10, false);
var libImage:getDefinitionByName(sceneData[curScene]) = new getDefinitionByName(sceneData[curScene])();
var currentBG:Bitmap = new Bitmap(libImage);
var bgFade:Tween = new Tween(mc_bg, "alpha", Regular.easeInOut, 0, 100, 100, false);
Attached is a basic starter project for you to look at.
Note: Download GSAP
for the tweens.
Copy the included "com" folder into the same folder as the FLA.
Clicking the "start" button will add the first scene and remove the button.
Clicking a scene will add the next scene and remove the previous scene.
The backgrounds are built into the scenes.
ie: scene1, scene2, scene1, scene2, etc...
Yeah, AS3 is very complex. Trying to go from AS2 to AS3 now, lol.
Here's example AS3 code that is as OOP free as possible. I shows good ways to do common programming stuff in AS3 - add clips dynamically to stage from library, use arrays of objects to store everything.
Check it out.
Click Here to Expand Forum to Full Width
Poll by Flashkit.com