Groups | Blog | Home
all groups > flash (macromedia) > march 2004 >

flash (macromedia) : problems with an array inside a Class


Xesko
3/16/2004 10:24:51 PM

Hi every one,

I'm pretty new to ActionScript (2.0), and I'm experiencing a weird
problem. I declare several properties in a Class which I extend from
the MovieClip Class. One of them is an array, to which I push values in
one of the defined methods. The thing is that this array behave as if
it's "static" (when it shouldn't), and only one "instance" of it gets
created, instead of one per each instance of the class, so I'm actually
pushing values to a single array instead of to different arrays
belonging to different instances (hope I'm making sense here). Am I
missing domething? May be there is some special way to deal with arrays
inside a Class...

Well, any comments or tips welcome.

Many thanks in advance,

Dinghus
3/16/2004 10:31:29 PM
Have you done the full path to the array?

Object1.myArray
Object2.myArray

Laiverd.COM
3/16/2004 11:14:15 PM
Think you may have to initialise the arry in the constructor.

John

--
----------------------------------------------------------------------------
-----------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
----------------------------------------------------------------------------
-----------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
----------------------------------------------------------------------------
-----------

Xesko
3/17/2004 4:20:30 PM
In article <c37v81$ksc$1@forums.macromedia.com>, Dinghus
[quoted text, click to view]

Thanks John and Dinghus,

I did tried to initialize the array in the constructor (giving it a
first value there), and the paths are correct. Is the same path I use
to give values to other properties, and they behave properly. I just
don't know why this is happening.
I also buit a very simple case to see if the problem was really there
or somewhere else in my code, but the new test behaved in the same way.
Here is what I have set up:

- I define a class (extending the MovieClip class) with two properties:
a simple variable and an array.
- I also define a stupid method that the only thing it does is push a
value I send along as an argument.
- I create a movieclip in the library, and connected to the Class in
its link section.
- In the timeline, I attach two instances of the movieclip from the
library (through attachMovie)
- then I call the method for them and pass a different value to each
instance
- Then I just "trace" the array on each of them.
- The result of the trace is the same in both cases, and there are the
two values in both arrays, because actually there is only one. Despite
the fact that I call the method to push values with the name of the
instances and not the class. No static property is defined.

I just don't understand, I don't know if I'm missing something here...

Any other clues welcome. Thanks a lot in advance,

Xesko
3/17/2004 4:49:33 PM

Hi all,

Just let you know that I found what was wrong.
The problem was that I was declaring the array inside the Class itself,
like any other property. This doesn't work like I wanted. The trick is
to declare it first inside the class like any other property, and
declare it as an array ( = new Array()) inside the constructor of the
class. Then it does work as I expected. Well, learning OOP and AS 2.0
in the hard way ;-)

Thanks a lot again for your help and clues.

Xesko.



In article <170320041620302151%xesko@skynet.be>, Xesko
[quoted text, click to view]
AddThis Social Bookmark Button