Affect movieclip scale from a .as doc to another
Posted
by
Madcowe
on Game Development
See other posts from Game Development
or by Madcowe
Published on 2012-10-18T17:15:52Z
Indexed on
2012/10/18
17:26 UTC
Read the original article
Hit count: 404
flash
|actionscript-3
I've been working on a game following a tutorial on the internet, the game is an avoider where you have the Avatar, that has to avoid the objects that fall.
The way it is made is: I have a DocumentClass which addChild's the screen you should be seeing and removeChild's the screen that you were.
For example: first it loads the menuScreen, then when you press play unloads menu and loads playscreen. When you die it loads the gameoverScreen and loads the playscreen.
And from the gameOverScreen you can press the SHOP button to go to the shop. From here on I'm on my own and not following any tutorials.
The shop has a button that is supposed to alter the Avatar's X and Y scale to 0.5, but the problem is: how do I make that work?
I tried creating a sharedObject.data.avatarSize, on the store's size button the code would be something like:
sharedObject.data.avatarSize *= 0.5;
And on the AvoiderGame.as, which is the most of the actual game, on the part where the avatar is created I tried putting this after it's creation:
scaleX.avatar = sharedObject.data.avatarSize;
scaleY.avatar = sharedObject.data.avatarSize;
This did not work since it gives me the error 1009 saying can't access something that is null. I tried this before "using" the sharedObject:
if( sharedObject.data.avatarSize == null )
{
sharedObject.data.avatarSize = 1;
}
But it did not work...
So now I'm not sure on what to do. I know we should reduce global variables as much as we can but how do I do it?
Also, if it helps, I'm using Flash CS5 and working with AS3.0
© Game Development or respective owner