This content has been marked as final. Show 7 replies
because flash 8 is backwards complient, you can actually just drop that bad boy on frame one of your movie, and it'll extend the Array class for you. Just make sure that thing is at the top somewhere, rather than burried.
Thank you very much Mr mcHelpson for your willingness to help me. I'm trying to learn how to do things in the best possible Colin Moock Actionscript 2 OOD/OOP way and thus don't put any code on my movies other than to instantiate my application's main class. So I would be needing to access this shuffle method from deep inside some other class stuff. Given that, do you have any futher direction for me on how to do this in the Actionscript 2 style? If you know how, I would be much obliged if you could spell it out for me. I'm very much a newbie.
I believe that code is from kglad. You can extend the Array Class. Code attached.
> collection.remove("David"); //no offense intended here David
No offense taken. Sometimes I do get busy and fall off the face of the
earth for a while. ;) Always glad to be back, though.
>> I'm trying to learn how to do things in the best possible Colin
>> Moock Actionscript 2 OOD/OOP way and thus don't put
>> any code on my movies other than to instantiate my
>> application's main class.
Flash is a tremendously versatile, flexible tool -- and I recommend any
of Colin Moock's books unequivocally -- at the same time, I find in my own
work that it really is okay to use the timeline for code, even in an
otherwise "all AS2 class" application. For example, I don't hesitate for a
second to put a simple stop(); action among various frames in movie clip
assets ... it's simply less hassle than targetting instances of those clips
and checking to see when any of them has reached, say, frame 112 (or
subclassing them and doing the same).
So aim for OOD, for sure (I'm definitely a fan), but take care not to
let that pursuit overshadow fundamentals -- such as understanding
Object.prototype, the difference between random() and Math.random(), and so
on. And that all comes with time. The learning never stops. ;)
It really isn't necessary to subclass Array here at all (though there's
nothing wrong with doing so). If it makes sense in your particular project
to have an Array that can also shuffle, LuigiL's example looks like it fits
the bill beautifully (great code!). You might, however, simply need a
utility function/method that shuffles a plain-vanilla Array. Again,
ActionScript is capable of all of that -- the choices are yours! -- and it's
Choice I find even more powerful than the well-earned respect many people
have for object-oriented design.
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."
Man, did I had a good laugh! I was typing up that code, using an array with numbers and suddenly thought let's take some names from the forum. And yes, David is online!
Well, no, in general there is no need to subclass Array. A simple function can do the trick. But, as I said, 'you CAN extend Array'. She could probably have a Collection class that has some functions to work with arrays.
....I'm still smiling here!
Again, I am so much obliged to all of you for your patient help.
LuigiL you are always so generous in providing me with wonderful useful code that I not only can use but always learn from. One follow on question if you don't mind.
In this statement:
I assume this means that I now have 2 arrays in memory, one called shuffled and one called collection. Is that correct? If I said:
collection = collection.shuffle();
would I have just one in memory and would this statement work?
No, shuffled merely holds a reference to the original array 'collection' so you don't have two arrays on the stack.