Skip to main content
May 26, 2010
Question

Why won't this data respond?

  • May 26, 2010
  • 1 reply
  • 943 views

using a setter to set an array but it's not tracing. ignore the super's they're working.

////////////////////

package {
   
    public class super_example extends real_class {
       
        private var myArray:Array;
       
        public function super_example() {
            trace("I am the text contained in the main class");
            if (myArray != null) {
                super("hi");
            }
            super.another_function();
        }
       
        public function set array(ar:Array):void {
            myArray = ar;
        }
       
        public function get array():Array {
            return myArray;
        }
       
        public function nother_example() {
            trace(myArray);
        }
    }
}

//////////////////

FLA FILE

var superClass:super_example = new super_example();
var myArray:Array = new Array("1","2","3","4");

btn_mc.addEventListener(MouseEvent.CLICK,work,false,0,true);

function work(e:MouseEvent):void {
    superClass.array = myArray;
    superClass = new super_example
    superClass.nother_example();
    trace(superClass.array);
}

trace(myArray);

////////////

Trace statement after clicking

I am the text contained in the main class
I am the text passed in another function
1,2,3,4
I am the text contained in the main class
I am the text passed in another function
null
null

This topic has been closed for replies.

1 reply

May 26, 2010

In function work you are assigning to superClass var a new instance of super_example object which has the myArray empty.

While you try to trace this array in the next two lines the superClass refers to this new instance instead.

function work(e:MouseEvent):void {
    superClass.array = myArray;
     superClass = new super_example
    superClass.nother_example();
     trace(superClass.array);
}

May 26, 2010

Ok makes sense, lastly how can I initiate a class file without making a new one?

May 27, 2010

What do you mean by initiate?