views:

50

answers:

2

This is basically the opposite of what I was trying to do earlier. I just need to know how to change a subclass variable from it's superclass. So if I were to make an object in a class how would I dynamically change a variable in that object from the original class that I made it in?

Suppose this is the main function of my main class:

        public function MAIN()
        {
  new OBJECT_square().CREATE(this,100,100);
  OBJECT_square.X = 40;
        }

Changing the X value in this way is not working. I realize I can set/change the X value when I make a new subclass but I need to be able to change it as I go. I also realize I can change it from within the subclass but this isn't what I want.

A: 

I am not sure what you are trying to do, perhaps you can elaborate, but this works:

public class MainClass() {

    protected var X:Number = 0;
   ...

}

public class SubClass extends MainClass() {

   ...

}

var subClass:SubClass = new SubClass();
subClass.X = 40;
sberry2A
+1  A: 

Your terminology is a bit screwed up. Rather than super- or subclass you actually mean parent and child class, or more precisely parent container and child component.

Anyway your problem is unrelated to this. What you need to do is access the new instance through a temporary var. Here's the fix:

public function MAIN()
{
    var square:OBJECT_square = new OBJECT_square();
    square.CREATE(this,100,100);
    square.X = 40;
}
Gunslinger47
For information on what subclasses really are, see here: [w:Subclass (computer science)](http://en.wikipedia.org/wiki/Subclass_%28computer_science%29)
Gunslinger47