PDA

View Full Version : Basic Working with Classes



coggia
July 25th, 2008, 05:30 AM
Hello, I'm new to AS3 so I try to code 'by the book' and try to forgot my old procedurials methods of coding :\

So i'm trying to interact with classes:
-I got 2 classes (class1,class2)that extends movie clip, each classes got its own properties (like .name )
-I got another Class called 'Time' that act like a Timer, and at Each Time.Event should trace each .name properties of the precedent Classes on the stage.

How can I touch the Classes whitin the Time Class ? If i'm not too confuse, of course

Recap : 1swf that create 2 classes (class1, class2) and create another Class (Time) that should be able to see the other Class properties.

spectator
July 25th, 2008, 07:11 AM
import yourClassName;

senocular
July 25th, 2008, 08:21 AM
You need to provide your Time instance with access to your other class instances, either by providing it with a reference to stage/root, or by giving it references of the instances directly. These can be passed into the constructor or added through a custom Time method not too unlike addEventLister or Array.push to give Time the objects it needs to work with.

coggia
July 25th, 2008, 08:52 AM
Okay,
thanks for guiding me ,
I guess i'll continue working by passing the stage reference to the class..

Hoping it's not a bad use of coding, like coding with (_root) was :)

thanks again

senocular
July 25th, 2008, 10:19 AM
well working with stage and root references can be depending on how you use them. Usually its not a good idea (practice-wise) to use them as a starting point to traverse the display list and grad references from nested movie clips, especially if by name since this confines your class to systems of a specific structure when one of the goals of OOP (and classes) is to have something reusable and portable. You're pretty much doing the _root thing again, only you now you just have to make sure _root (root) is accessible.