Groups | Blog | Home
all groups > flash actionscript > october 2005 >

flash actionscript : Can someone help me out with this?


TruLine
10/29/2005 11:45:24 PM
Can someone decifer this for me... I am trying to get going with classes and
static abilities, and I got this to get me going...

class Users {
private static var numInstances:Number = 0;
function Users() {
numInstances++;
}
static function get instances():Number {
return numInstances;
}
}


Create a FLA or AS document in the same directory, and enter the following
ActionScript in Frame 1 of the Timeline:

trace(Users.instances);
var user1:Users = new Users();
trace(Users.instances);
var user2:Users = new Users();
trace(Users.instances);

This is BULLSHIT!!! for one, what can I possibly get from this example?????
How many instances of a movie clip are created...Maybe????? I thought the Idea
of static principles were of this nature..."newMC = myClass.manipulateMC(oldMC)"

Can someone PLEASE chang this code a bit so to fit a sensible scenario??!!??!!

I have recieved a lot of help on this board, and I do appreciate it. I just
wished that these guys who write these books were not so amart, or, lived in
the real world before they became a programmer. using "foo" and "bar" =
"foobar" does no one an ounce of good... Use Foobar to explain the nation's IT
industry!!

TruLine
10/30/2005 12:00:00 AM
okay...I feel better today...

They say sex sells...let's try it. I am redoing our example above and
throwing in some questions...

class Base {
private static var howFarDidYouGet:Number = 0;
function Base() {
howFarDidYouGet++;
}
static function get progress():Number {
return howFarDidYouGet;
}
}

trace(Base.progress); //Shows 0

I know I can't get to first base on my own...(no I'm not a loser! lol...) so,
I'm gonna use a "girlfreind to influence her friend...

var girlfriend1:Base = new Base();

Now, at the party when you recieve the "rabid" questioning about your date
last night, you can answer with a simple statement...well guys, Base.progress!!
trace(Base.progress); //returns 1...

So, we're cool so far right??

Now...we find out that we're toast with the girlfriend bacause some bozo at
the party told her what you said about her friend. So, we have to try another
way to get to the next base... Let's read some self help books(MovieClips)

howToWinFriendsAndInfluencePeople_mc //mc-1
womenAreFromVenusMenAreFromMars_mc //mc-2
dating101_mc //mc-3

Now, let's say the follwing tell our heart throb how serious we are about her.
how do we get to the next base by using one of the follwing methods...

this.onPress...
mc_1.hitTest...
mc_2.hitArea...
mc_3.onMouseMove...
mc_1.getBounds...
mc_2.attachMovie...
mc_3.duplicateMovieClip...
etc...
etc...
etc...

Okay, I did enough thinking this morning and have to go take a cold shower!
if you'all could help get to the next base, we all will learn something here I
think.

Indeed a static method is usefull...I see it. I am trying to learn how to use
it to my benifit.

Tim



sampurtill
10/30/2005 8:29:51 AM
Hahahaha you have a point. However that code makes sense, the only problem I
have with it is when the first trace is called what does it come back as equal
to? Since you didnt initiate your Users class I dont know if it should come
back as anything. But yeah the rest of the code should just be fine, I donno
why youre complaining. And watch the language when youre posting, I dont have a
problem with it but Macromedia does

-

Cheers/Sam
codescodescodes
10/30/2005 10:41:12 AM
ok TruLine,
I know things can get frustrating sometimes. I'm in the same boat
as you are. I'm not an expert. I'm just learning also and there have been
many times when I want to rip my hair out and cussing at books and wondering
what the @##$$% they're trying to say. After letting myself kick my ass a
couple of times, I find that the best way to approach this type of situation is
to step back and take a break. You're not going to get everything the first
time you read it. You're not going to get everything the second time you read
it. And if you do GET IT, sometimes you'll forget it. It's a learning
process. Sometimes you read one book and it just doesn't make sense no matter
how many different angles you look at it or how many times you go over it, but
if you read the same topic in another book explained a different way, it just
clicks. What I'm trying to say is don't beat yourself up. You're not the only
one who doesn't get it sometimes. Take your time. Read it again and again and
again if you have to. Read different books from different publishers. It
useless blaming the book or the author. Anyways enough of my preaching, let me
try to help you with what you're getting caught up on.

The code seems fine. You might not be understanding what a static member is
supposed to be used for. What a static member does is it lets you access a
member without having to instantiate the class. This is how you would
normally call a method of a class:

var myClass1:myClass = new myClass();
myClass1.someMethod();

With a static member you would do it like this:

myClass.someMethod();

see how you don't have to create an instance of the class. You just use the
class name itself followed by the method.
Hope that makes sense, and let me guess, you're reading the red ActionScript
2.0 Dictionary right.
AddThis Social Bookmark Button