Be a Supporter!

static class troubles

  • 311 Views
  • 5 Replies
New Topic Respond to this Topic
mikeMarek
mikeMarek
  • Member since: Jan. 24, 2008
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
static class troubles Jun. 14th, 2012 @ 01:13 PM Reply

...I can't believe I'm posting this... Sorry for the relatively "simple" question, but here goes.

So, I've been using a static class called Maths that contains my own mathematical functions (such as significant figure rounding, angle and distance functions, etc.). I made it static for the same reasons AS3 makes it's Math class static; to avoid declaring a class instance to reference internal functions.

My troubles arise when I reference these static functions inside of another class. They work perfectly fine when called upon the stage:

//this is on the stage/Document class
import engine.utils.Maths;
trace(Maths.FOOBAR());

Yet do not work when called upon inside of my own classes:

//this is in a custom class
package engine
{
	import engine.utils.Maths;
	
	public class Shapes
	{
		public function Shapes():void
		{
			trace(Maths.FOOBAR());
		}
	};
};

And yet, oddly enough again, works perfectly fine when using FlashDevelop, but when making small demo projects in Flash itself, gives me the ever fruitful error message:

1061: Call to a possibly undefined method FOOBAR through a reference with static type Class.

I've really stumped myself here... No amount of Google could help me... I would appreciate any help you guys could offer, or alternative solutions suggested.

Again, thanks a lot Newgrounds community, you're always so helpful and friendly :)

Best regards,
Mike


BBS Signature
ProfessorFlash
ProfessorFlash
  • Member since: Oct. 6, 2007
  • Offline.
Forum Stats
Member
Level 32
Programmer
Response to static class troubles Jun. 14th, 2012 @ 01:26 PM Reply

Flash can't find the class. So in a nutshell: "engine.utils.Maths" path is wrong. Find out where the class really is located. And tbh, I don't understand why you are trying to make it work in flash when you say you have flash develop and everything works fine there.


You can solve pretty much any problem you may have with AS3 by consulting the AS3 Language reference.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Member
Level 05
Game Developer
Response to static class troubles Jun. 14th, 2012 @ 01:30 PM Reply

At 6/14/12 01:13 PM, mikeMarek wrote: ...I can't believe I'm posting this... Sorry for the relatively "simple" question, but here goes.

So, I've been using a static class called Maths that contains my own mathematical functions (such as significant figure rounding, angle and distance functions, etc.). I made it static for the same reasons AS3 makes it's Math class static; to avoid declaring a class instance to reference internal functions.

My troubles arise when I reference these static functions inside of another class. They work perfectly fine when called upon the stage:

//this is on the stage/Document class
import engine.utils.Maths;
trace(Maths.FOOBAR());

Yet do not work when called upon inside of my own classes:

//this is in a custom class
package engine
{
import engine.utils.Maths;

public class Shapes
{
public function Shapes():void
{
trace(Maths.FOOBAR());
}
};
};

And yet, oddly enough again, works perfectly fine when using FlashDevelop, but when making small demo projects in Flash itself, gives me the ever fruitful error message:

1061: Call to a possibly undefined method FOOBAR through a reference with static type Class.

I've really stumped myself here... No amount of Google could help me... I would appreciate any help you guys could offer, or alternative solutions suggested.

Again, thanks a lot Newgrounds community, you're always so helpful and friendly :)

Best regards,
Mike

Maths - you Englanders are going to drive me crazy with your grammar xD

anyway - i'm not sure exactly what's going on (as we don't have the actual class), but I did a quick google and it came up with some possible solutions

I know you already said you've googled it, but maybe I used different wording. Check it out anyway :P


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
Sam
Sam
  • Member since: Oct. 1, 2005
  • Offline.
Forum Stats
Moderator
Level 19
Programmer
Response to static class troubles Jun. 14th, 2012 @ 01:32 PM Reply

Maths - you Englanders are going to drive me crazy with your grammar xD

Mathematics
Maths

mikeMarek
mikeMarek
  • Member since: Jan. 24, 2008
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to static class troubles Jun. 14th, 2012 @ 01:40 PM Reply

@ProfessorFlash: It's not the pathing that's wrong; I tried calling non-static methods from a completely different class located in the same path, and it works fine.

@egg82: I'm Canadian, I only used Maths since it's similar to Math and it keeps naming conventions pretty easy to remember lol. I thought the same thing upon creating the class though, "let's use American spelling convention for this!"
The Google page, however, had every link purple'd out except the first link haha. I already skimmed through most of them lol. I will try wording everything differently in some future searches, so thanks for the hint.
Love the signature btw, same reason I became a programmer :3

I'll re-post this as SOLVED if I ever do figure this out... Thanks for the couple of posts though! Quick responses, you guys are great!


BBS Signature
mikeMarek
mikeMarek
  • Member since: Jan. 24, 2008
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to static class troubles Jun. 14th, 2012 @ 02:01 PM Reply

HAHAHAHAHAHHAHAHAHAHAHHA

You guys aren't gonna fucking believe this....

It had to do with the LITERAL naming of the class...

I changed the class name to Mathz (you know, because every cool mathematician spells with a Z) and it worked like a charm... I swear to God if I ever meet the designer of AS3 I'm gonna punch him it the skull...

So, I guess you could say this thread is RESOLVED.

Thanks for those two posts ProfessorFlash and egg82, sending good vibes your way :)

Cheers,
Mike


BBS Signature