-----------------------------

In your bit of code:

Myclass extends Array {
        ... Constructor and Other needed elements
}
Myclass[index]

I don't think you could ever do that with an array without actually making a
new Array (); so to be able to access the array elements that way, try
using:

var myArray = new Myclass ();
myArray [ index ];

...same as 

var array = new Array ();
array [ index ];

-----------------------------

Not sure if this helps or complicates things - but here are a few approaches
of instances working with static methods/properties of the extended Array
class.

//
//      EXAMPLE 1
//

In this example, the preset array values are set through the constructor,
and you can change that at anytime. Each new instance has internal
properties as well and a few different ways in which to talk with the Static
class.


///////////////////////////// in EXAMPLE_1.fla


//      import
        
                import ArrayExt;
        
//      set future array defaults
        
                ArrayExt.setDefaults ( [ 'a', 'b', 'c' ] );
        
//      create
        
                var array1 = new ArrayExt ( );
        
//      set new defaults
        
                ArrayExt.setDefaults ( [ '1', '2' ] );
        
//      create
        
                var array2 = new ArrayExt ( );
                var array3 = new ArrayExt ( 'blah', 'blah', 'blah' );
                
//      output

                trace( '\nArrayExt.defaultArray: ' + ArrayExt.defaultArray )
// 1,2
                
                trace( '\narray1: ' + array1 ); // a,b,c
                trace( 'array2: ' + array2 ); // 1,2
                trace( 'array3: ' + array3 ); // 1,2
                
                trace( '\narray1.length: ' + array1.length );// 3
                trace( 'array2.length: ' + array2.length );// 2
                
                trace( '\narray1[0]: ' + array1[0] );// a
                trace( 'array2[0]: ' + array2[0] );// 1
                
                trace( '\narray1.internalVal_0: ' + array1.internalVal_0
);//333
                trace( 'array2.internalVal_0: ' + array2.internalVal_0
);//333
                trace( 'array3.internalVal_0: ' + array3.internalVal_0
);//333
                
                trace( '\narray1.fullArray: ' + array1.fullArray );//
X,X,X,a,b,c
                trace( 'array2.fullArray: ' + array2.fullArray );//
X,X,X,1,2
                trace( '\narray1.fullLength: ' + array1.fullLength );// 6
                trace( 'array2.fullLength: ' + array2.fullLength );// 5


///////////////////////////// in ArrayExt.as

class ArrayExt extends Array
{
        public static var defaultArray:Array;
        public static var intervalArray:Array = [ 'X', 'X', 'X' ];

        public var internalVal_0:Number = 3333;
        public var internalVal_1:Number = 9999;

        public function ArrayExt ()
        {
                trace( ArrayExt () - arguments : ' + arguments );
                INIT ();
        }

        //      PUBLIC 
        
        //      getters and setters
        
        public function get fullArray ():Array 
        {
                return ArrayExt.intervalArray.concat ( this );
        }
        
        public function get fullLength ():Array
        { 
                return ArrayExt.intervalArray.length + this.length;
        }

        //      PUBLIC STATIC

        public static function setDefaults ( array:Array ):Void
        {
                defaultArray = ( array == undefined ) ? [] : [].concat (
array );
        }

        //      PRIVATE

        private function INIT ()
        {
                // default
                for ( var i in ArrayExt.defaultArray )
                {
                        this [ i ] = ArrayExt.defaultArray [ i ];
                }
        }
}



-----------------------------

//
//      EXAMPLE 2
//

What it comes down to is how exactly you want to use this. If you just want
a class that allows you to have some extra control over the array you can
always make a simple array class with access to a Array utility class.


///////////////////////////// in EXAMPLE_2.fla

var array = new ArraySimple ( 'a', 'c', 'b', 1, 7, 3 );

trace( 'array.sorted: ' + array.sorted );
trace( 'array: ' + array );
trace( 'array[0]: ' + array[0] );


///////////////////////////// in ArraySimple.as

import ArrayUtils;
class ArraySimple extends Array
{
        public function ArraySimple () 
        {
                for ( var i in arguments ) 
                {
                        this [ i ] = arguments [ i ];
                }
        }

        public function get sorted ():Array
        {
                return ArrayUtils.sortArray ( this );
        }
}

///////////////////////////// in ArrayUtils.as

class ArrayUtils
{
        public function ArrayUtils  () {
        }

        public static function sortArray (array:Array )
        {
                var a = [].concat ( array );
                a.sort();
                return a;
        }
}


_____________________________

Jesse Graupmann
www.jessegraupmann.com 
www.justgooddesign.com/blog/ 
_____________________________



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Stepanenko,
Nikolai A.
Sent: Tuesday, May 22, 2007 4:34 PM
To: flashcoders@chattyfig.figleaf.com
Subject: [Flashcoders] Extends Array ???

Has anyone been able to get the indexer working by extending Array
class?

Like

Myclass extends Array
{
        ... Constructor and Other needed elements
}

!!! Usage I am looking for:

Myclass[index]

One of the properties of the prototype is length. It actually gets set
on Myclass during extension of Array but I haven't figure out how to set
the index to respond with at least internal value. Ultimately I would
like to use this in static mode as an actual type.

So this would be in some way custom prebuilt array.

Any other alternatives are appreciated, thank you!

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to