0
\$\begingroup\$

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?

--EDIT--

Also, if it helps, I'm using Flash CS5 and working with AS3.0 and if you don't know about flash, you can also tell me how you would do it on any other language and I would try to convert it to flash.

\$\endgroup\$
2
  • \$\begingroup\$ Well I'm not to familiar with flash, but it seems like your ScaleX or ScaleY struct/class was never initialized. If your avatar is just a sprite it should be as easy as changing the sizes speicified in your draw code to the (image width * avatar size, image height * avatar size) \$\endgroup\$ Oct 18, 2012 at 17:46
  • \$\begingroup\$ Actually the scaleX and scaleY are actually flash functions that affect the X and Y scale respectively. But the real problem is the sharedObject I'm making is making the program tell me it is null, if I remove the lines of that IF statement it doesn't give me the error. \$\endgroup\$
    – Madcowe
    Oct 18, 2012 at 18:23

1 Answer 1

0
\$\begingroup\$

Solved it!

I had to do a lot of work for it to work though, but it seems to have been mostly a distraction on my part.

Had to create the sharedObject var on the .as files it was used in, which I had already done, but I also had to associate them with the save file where they were, of course!

Then after that the code didn't really give me much trouble, thanks though, I only managed with some tips and tricks from here.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .