Be a Supporter!

Error this = new Movieclip()

  • 310 Views
  • 7 Replies
New Topic Respond to this Topic
Momo-the-Monkey
Momo-the-Monkey
  • Member since: Oct. 15, 2005
  • Offline.
Forum Stats
Member
Level 45
Musician
Error this = new Movieclip() 2012-09-29 11:17:48 Reply

I'm trying to do something like this:

public class Ball extends MovieClip {
   public function Ball(){
      var ballClass:Class = getDefinitionByName('BallMC_' + ballNames[type]) as Class;
      this = new ballClass();
   }
}

I'm getting an error "Cannot assign to a non-reference value." I was just wondering if there was a way to achieve this, or if I'm just going to have to use a different method?

Thanks.


Hello, from the past!
[ PHP: Main ]

BBS Signature
PSvils
PSvils
  • Member since: Feb. 3, 2010
  • Offline.
Forum Stats
Member
Level 01
Game Developer
Response to Error this = new Movieclip() 2012-09-29 12:18:29 Reply

At 9/29/12 11:17 AM, Momo-the-Monkey wrote: I'm trying to do something like this:
I'm getting an error "Cannot assign to a non-reference value." I was just wondering if there was a way to achieve this, or if I'm just going to have to use a different method?

Thanks.

What exactly is the point of that Constructor???

Momo-the-Monkey
Momo-the-Monkey
  • Member since: Oct. 15, 2005
  • Offline.
Forum Stats
Member
Level 45
Musician
Response to Error this = new Movieclip() 2012-09-29 14:16:52 Reply

At 9/29/12 12:18 PM, PSvils wrote: What exactly is the point of that Constructor???

Well it doesn't necessarily have to be the constructor. I would link an object from the library to this class, but as you can see I want multiple items from the library to be able to be used under this class (which as3, for obvious reasons, does not allow).

I could, of course, create a class for each object I want to use and have that class extend this class, but that would create a ton of extraneous classes. I could do it (or forget extending completely by using a variable inside that class that is linked to the objects), but I wanted to see if there was a way similar to the above that would work.


Hello, from the past!
[ PHP: Main ]

BBS Signature
egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Error this = new Movieclip() 2012-09-29 14:21:11 Reply

At 9/29/12 02:16 PM, Momo-the-Monkey wrote: Well it doesn't necessarily have to be the constructor. I would link an object from the library to this class, but as you can see I want multiple items from the library to be able to be used under this class (which as3, for obvious reasons, does not allow).

this looks like an X Y problem. What exactly are you trying to achieve by doing all of this?


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

BBS Signature
Momo-the-Monkey
Momo-the-Monkey
  • Member since: Oct. 15, 2005
  • Offline.
Forum Stats
Member
Level 45
Musician
Response to Error this = new Movieclip() 2012-09-29 14:24:36 Reply

At 9/29/12 02:21 PM, egg82 wrote: this looks like an X Y problem. What exactly are you trying to achieve by doing all of this?

An X Y problem? I'm not sure I follow. And I'm just trying to link multiple objects in the library to a single class. So let's say I have a blue ball and a red ball and a green ball. I want each of them to use this class.

I know there are other ways of achieving this (not extending MovieClip), but I just wanted to see if this method would work.


Hello, from the past!
[ PHP: Main ]

BBS Signature
egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Error this = new Movieclip() 2012-09-29 15:15:27 Reply

At 9/29/12 02:24 PM, Momo-the-Monkey wrote: An X Y problem? I'm not sure I follow.

an X Y problem is a problem in which you have problem X and think solution Y is best, then ask about problem Y when there may be a better solution to problem X.

And I'm just trying to link multiple objects in the library to a single class. So let's say I have a blue ball and a red ball and a green ball. I want each of them to use this class.

instead of MovieClip or Sprite? Just set the "Export for Actionscript" settings to use that class instead of flash.display.MovieClip

Though i'm curious as to why you need to write an entire DisplayObject.

I know there are other ways of achieving this (not extending MovieClip), but I just wanted to see if this method would work.

Why are you testing this particular method? Why not simply use something pre-made?

And what is the entire purpose of setting the balls to use another class? What is problem X?


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

BBS Signature
Momo-the-Monkey
Momo-the-Monkey
  • Member since: Oct. 15, 2005
  • Offline.
Forum Stats
Member
Level 45
Musician
Response to Error this = new Movieclip() 2012-09-29 15:41:08 Reply

At 9/29/12 03:15 PM, egg82 wrote: instead of MovieClip or Sprite? Just set the "Export for Actionscript" settings to use that class instead of flash.display.MovieClip

Aye yai yai, that's a nice solution. I never considered using the Base class.

Why are you testing this particular method? Why not simply use something pre-made?

I was just curious if I could use one class flexibly with multiple objects. I couldn't use something pre-made because quite honestly I wasn't sure what to look for.

And what is the entire purpose of setting the balls to use another class? What is problem X?

The purpose was to be able to use a single class with multiple objects specified at runtime, without using variables as the controlling factor (i.e. using the class as an extension). Using the base class seems to solve this problem. I apparently was unaware exactly the difference between base class and class. I was also not thinking about using the base class other than flash.display.MovieClip. Sorry for not realizing this was an X Y problem, haha. Thanks


Hello, from the past!
[ PHP: Main ]

BBS Signature
MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Error this = new Movieclip() 2012-09-29 16:04:14 Reply

Then yeah, use a base class, make a class called Shapes it may even just be empty or contain variables and function that would apply for all Shapes, then have each shape extend it.

Then you can do this:

var s:Shape;
s = new Ball();
s = new Box();

et cetera, you can assign it to anything exending Shape.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature