mrGott
mrGott

Reputation: 1076

Arrays in AS3.0 OOP

I'm trying to figure out how to work with arrays in OOP AS3.0. Have been looking for the answers or some tutorial and can't find it. Maybe you can explain.

This is what I've got:

Gallery.as file:

package  {

    import flash.display.MovieClip;


    public class Gallery extends MovieClip {

        public var can:Number;

        public function Gallery() {


            can = 10;

            var impMyClass:Read = new Read(can);
            trace (impMyClass.myArray[0]);

        }

}

}

and here's Read.as file:

package  {

    import flash.display.MovieClip;


    public class Read extends MovieClip {

        public var rezalt:Number = new Number;
        public var myArray:Array = new Array;

        public function Read(can:Number) {

            rezalt = can * 10 - 50 / 10;
            trace('Read-shi')


        myArray.push('Flash');                      


        }
    }
}   

So far everything works just fine.

but when I make some changes in Read.as file like this:

package  {

    import flash.display.MovieClip;


    public class Read extends MovieClip {

        public var rezalt:Number = new Number;
        public var myArray:Array = new Array;

        public function Read(can:Number) {

            rezalt = can * 10 - 50 / 10;
            trace('Read-shi')
        }

        public function someFunct():void{

        myArray.push('Flash');                      


        }


    }
}   

everything breaks down. How should I get the value of myArray into the main Class file (Gallery.as)?

Upvotes: 0

Views: 491

Answers (3)

Tareq Rahman
Tareq Rahman

Reputation: 61

You're pushing wrong:

You should type:

myArray.push(Flash); *trace(myArray.length);*

Upvotes: 0

Tareq Rahman
Tareq Rahman

Reputation: 61

Try this:

package {

import flash.display.MovieClip;


public class Read extends MovieClip {

    public var rezalt:Number = new Number;
    public var myArray:Array = new Array;

    public function Read(can:Number)**:Number** {

        rezalt = can * 10 - 50 / 10;
        trace('Read-shi')
    }

    public function someFunct():void{

    myArray.push('Flash');                      


    }


}

}

Upvotes: 0

Mattias
Mattias

Reputation: 3907

You need to run the function "someFunct" in your last version of Read.as otherwise the Array will not be populated.

    package  {

        import flash.display.MovieClip;


        public class Gallery extends MovieClip {

            public var can:Number;

            public function Gallery() {


                can = 10;

                var impMyClass:Read = new Read(can);
                impMyClass.someFunct();
                trace (impMyClass.myArray[0]);

            }

    }

}

Upvotes: 5

Related Questions