Forum Topic: Question about variables.

(100 views • 4 replies)

This topic is 1 page long.

<< < > >>
None

Rikimaru-Azlar

Reply To Post Reply & Quote

Posted at: 6/29/09 09:22 PM

Rikimaru-Azlar DARK LEVEL 19

Sign-Up: 01/14/01

Posts: 37

If you put conditions for a variable (say when player is hit by an enemy) within a function and set conditions for true and false,

can you then refer to that condition in other symbols? Like when enemy attack hit tests character set player hit to true - thus making the player respond to the hit event from within another movie clip. Is that possible?


None

Woadraiders

Reply To Post Reply & Quote

Posted at: 6/29/09 09:24 PM

Woadraiders DARK LEVEL 11

Sign-Up: 11/11/07

Posts: 561

Yes, and implemented just as you said it.

Mibbygames.com
panterA

BBS Signature

None

Rikimaru-Azlar

Reply To Post Reply & Quote

Posted at: 6/30/09 09:35 AM

Rikimaru-Azlar DARK LEVEL 19

Sign-Up: 01/14/01

Posts: 37

At 6/29/09 09:24 PM, Woadraiders wrote: Yes, and implemented just as you said it.

Thanks dude, will get my head round this


Happy

WhoknowsmeaUdiO

Reply To Post Reply & Quote

Posted at: 6/30/09 11:18 AM

WhoknowsmeaUdiO DARK LEVEL 13

Sign-Up: 04/11/07

Posts: 1,170

To acces a variable that is inside another MC, you can put "_root." + the instance name of the MC, followed by the variable name. If you want to access the variable "variable1" from the MC "enemy", just use something like this:

if(_root.enemy.variable1 != 0){
_root.enemy.variable1 = 0;
}

If the variable is in a movieclip that's inside another MC, stack it. The most upper one first. MC "lawl" is inside MC "hello". On MC "lawl", there's the variable "haha".
So:

_root.hello.lawl.haha = 1002;

If you adress a distant variable often in your script, you can assign it to another variable:

onEnterFrame = function () {
	var movieclip = _root.lawl.variable1;
	trace(movieclip);
// I've already defined variable1.
};

But keep in mind that it's a lot better to keep your code together. Either on one MC or on the main timeline. In AS3, you can't even code on MC's.

In case you haven't noticed yet, this isn't my main anymore. PM me here.

BBS Signature

None

asgrunt

Reply To Post Reply & Quote

Posted at: 6/30/09 12:42 PM

asgrunt NEUTRAL LEVEL 01

Sign-Up: 05/26/09

Posts: 164

Yes, you can use _root, but you shouldn't - as soon as your movie is loaded via mc.loadMovie() nothing will work any longer. Use relative adressing instead, i.e.:

this._parent.something

And, yes, don't use object scripts anymore, they are ways to inflexible and wil get lost in complex projects


All times are Eastern Standard Time (GMT -5) | Current Time: 02:22 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!