PDA

View Full Version : Variables and adding.


FluffyPapes
12-24-2008, 06:35 PM
So, apparently something is going wrong because it's giving me the error of "Type mismatch found in assignment statement: found Number where money is required."

class money extends MovieClip
{
var money;

function onLoad()
{
money = 0;
}

function onEnterFrame()
{
if(_root.alexf.hitTest(this))
{
money ++;
_x = Math.random()*400;
_y = Math.random()*400;
trace(money);
}
}
}

That's my actionscript for the money, and I can't figure out what is wrong with it.

Also, when I took out the "money = 0;" in onLoad().. it started working. But the trace values under the hitTest gave me a "NaN"

CyanBlue
12-24-2008, 06:38 PM
What if you say var money:Number; ?

FluffyPapes
12-24-2008, 06:43 PM
I didn't think of that, but it still didn't work.

The source it says it's coming from is in the onLoad() function.

It's saying the problem is:

money = 0;

orange gold
12-24-2008, 06:45 PM
on the loading screen of your game put
_root.onEnterframe = function()
{
money = 0;
}

that way its not constantly setting the money to 0 whenever a new function is preformed

CyanBlue
12-24-2008, 06:47 PM
That does not really make sense...
What do you get with this???
class money extends MovieClip
{
var money:Number;

function onLoad()
{
money = 0;
}
}
Hm... Don't you need a constructor in AS2 class???

FluffyPapes
12-24-2008, 06:47 PM
on the loading screen of your game put
_root.onEnterframe = function()
{
money = 0;
}

that way its not constantly setting the money to 0 whenever a new function is preformed

The loading screen?

I don't have a loading screen haha.

and I don't do the coding in Windows> Actions [F9]

I make separate AS Files because I'm too used to Java

FluffyPapes
12-24-2008, 06:49 PM
That does not really make sense...
What do you get with this???
class money extends MovieClip
{
var money:Number;

function onLoad()
{
money = 0;
}
}
Hm... Don't you need a constructor in AS2 class???

By constructor what do you mean?
The point of that was because if I don't set the money to 0, it has no value. So if I get to the onEnterFrame() function, then there will be nothing to ++ to. If it's ++ing on a non-number, it'll return a value of NaN

orange gold
12-24-2008, 06:59 PM
The loading screen?

I don't have a loading screen haha.

and I don't do the coding in Windows> Actions [F9]

I make separate AS Files because I'm too used to Java
well just make a very first frame infront of everything hit f9 and copy paste that code onto that main frame and all your problems will be solved, from then on you can still continue to make seperate as files

FluffyPapes
12-24-2008, 07:04 PM
well just make a very first frame infront of everything hit f9 and copy paste that code onto that main frame and all your problems will be solved, from then on you can still continue to make seperate as files


Believe it or not, it didn't help.

It just added a second instance of the problem.

orange gold
12-24-2008, 07:08 PM
well you also have to delete the original one and make sure the code isnt on the frame with the real game. make it on a blank frame at the very start

CyanBlue
12-24-2008, 07:32 PM
I meant the constructor that you normally use in the class file like this...
//
class Money extends MovieClip {
var money:Number;

function Money()
{
money = 0;
}
}

FluffyPapes
12-24-2008, 07:44 PM
Oh, no.

You don't need that, the only requisite is that the class name and the AS file name needs to be the same

CyanBlue
12-24-2008, 08:28 PM
Well... I have made a quick example based on your code, and I don't get the error message... Can you compare it with yours or can you create a simple sample out of what you have???

FluffyPapes
12-24-2008, 09:06 PM
I fixed it.

It was getting an error because it was trying to get something from a different class.

I converged the classes and it works fine now

CyanBlue
12-25-2008, 08:19 PM
Cool... :)