Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables and movieclip instances 1

Status
Not open for further replies.

okiiyama

IS-IT--Management
Jan 3, 2003
269
0
0
US
I've been trying to think of the best way to ask this question, but I don't know how to word it exactly...

Anyways, I'm a little confused about creating, initializing and returning the values of variables on a timeline of a movieclip instance created in actionscript. Was that a run-sentence? Oh well.

So, on the main timeline I want to create X amount of movieclips using attachMovie(). The instance(s) of the created movieclips needs to have a variable to hold a url to an image. How/where do I create/declare the variable? Do I add that variable to the Movieclip timeline or can is this something I can do from the main timeline? Furthermore, how/where do/can I set the variable?
These questions aren't so much for the: "How do I do this?", but more for the "Why do I do it this way?".

I thought that I could do the following to display a trace of msgText on a rollOver.

In the movieclip's timeline:
Code:
var msgText = "";
this.onRollOver = function() {
  trace(this.msgText);
};
On the main timeline:
Code:
var a = this.attachMovie(.....);
a.msgText = "Some Message";
The trace doesn't display "Some Message", but it will if I remove: var msgText = ""; from the movieclip timeline. This is confusing.

 
You're creating a variable "msgText" dynamically and assigning the value "Some Message" to it in the movieclip instance from the main timeline but then re-declaring it and asssign the value "" in that movieclip.

If you do all the scripting in the main timeline you will not get into this kind of confusion and that's why it's a good practice to do it in this way.

Example:
[tt]// main timeline
this.attachMovie("mcX", "mcX1", this.getNextHighestDepth(), {_x:100, _y:100});
mcX1.msgText = "Some Message";
mcX1.onRollOver = function() {
trace(mcX1.msgText);
};
//[/tt]

Kenneth Kawamoto
 
Thank you. That'll be easier to see everything rather than having to edit the movieclip itself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top