Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Problem With Variables And Movie Instances



Okay I have another problem. Like my last one I have a main movie, a stage, and it loads 2 movies into it that are movie 1 and movie 2. I made them instances 1 and 2. In movie 1 I have a form with a name field. I want to make it pass the name variable to instance 2 when the form is submitted. How do I pass variables to the other instance. I tried making them global or make a path to the test field but it won't work. I want to display what is inputted in a dynamic text field in the other instance. What would be the best way to do this?



FlashKit > Flash Help > Flash ActionScript
Posted on: 03-22-2005, 12:26 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Problem With Variables And Movie Instances
Okay I have another problem. Like my last one I have a main movie, a stage, and it loads 2 movies into it that are movie 1 and movie 2. I made them instances 1 and 2. In movie 1 I have a form with a name field. I want to make it pass the name variable to instance 2 when the form is submitted. How do I pass variables to the other instance. I tried making them global or make a path to the test field but it won't work. I want to display what is inputted in a dynamic text field in the other instance.

Problems Accessing Variables In Movie Clip Instances
I am trying to build an application that will create multiple instances of a movie clip, each with a unique width and height that will be passed from a PHP script. Each of these will be draggable and 'rotatable' on the stage. The final positions will then be recorded and saved as a jpeg on the server(through PHP). For testing locally I am just using a text file (var.txt) with the following contents...

pic_w=340&pic_h=60&ic=007

I am having problems setting the width and height of the instances using the passed variables. Below is what I have put together so far. I have an empty movie clip with the following actionscript...

onClipEvent (load) {
for (i=1; i<4; i++) {
_root.attachMovie("mainLink", "mainInst"+i, 3+i);
loadVariables("var.txt", "_root.mainInst"+i, "POST");
eval("_root.mainInst"+i)._x = 100;
eval("_root.mainInst"+i)._y = 80*i;
}
}

onClipEvent (enterFrame) {
var pic_w = parseInt(/:pic_w);
var pic_h = parseInt(/:pic_h);
for (i=1; i<4; i++) {
eval("_root.mainInst"+i).pic_w = pic_w;
eval("_root.mainInst"+i).pic_h = pic_h;
}
}


The movie clip that is called above in the attachMovie with the linkage 'mainLink' has the following actions inside of it...

this.createEmptyMovieClip("box",20);
box.moveTo(0,0);
box.lineStyle(0, 0x333333);
box.beginFill(0xCC0000, 0)
box.lineTo(100,0);
box.lineTo(100,50);
box.lineTo(0,50);
box.endFill();

// I have been trying to access the width & height variables here
setProperty("box", _width, pic_w);
setProperty("box", _height, pic_h);

box.onPress = function () {
swapDepths(15);
startDrag ("");
}
box.onRelease = function () {
stopDrag ();
}

//create some formatting for our text box
txt_format = new TextFormat();
txt_format.font = "Verdana";
txt_format.size = 12;
txt_format.color=0x000000;

//create a blank text box and set its parameters
this.createTextField("txt_box",10,0,0,0,0); // start with default values
txt_box._width = box._width;
txt_box._height = box._height;
txt_box.background = true;
txt_box.backgroundColor = 0xEEEEEE;
txt_box.variable = "ic";

txt_box._x = box._x;
txt_box._y = box._y;

//format our text box
txt_box.setNewTextFormat(txt_format);

// this is a button in the library with the linkage 'turnLink'
this.attachMovie("turnLink", "turnInst", 35);
turnInst._x = box._x + (box._width/2)-(turnInst._width/2);
turnInst._y = box._y + (box._height/2)-(turnInst._height/2);

turnInst.onRelease = function() {
swapSize(box._height, box._width);
}

swapSize = function(new_w, new_h) {
// swap the current width and height
// to give the appearance of being rotated
setProperty("txt_box", _width, new_w);
setProperty("txt_box", _height, new_h);
setProperty("box", _width, new_w);
setProperty("box", _height, new_h);

//var diff = box._width - box._height;
var diff = getProperty("box", _width) - getProperty("box",

_height);

// reset the x and y positions
setProperty("box", _x, (box._x - diff/2));
setProperty("box", _y, (box._y + diff/2));
setProperty("txt_box", _x, (txt_box._x - diff/2));
setProperty("txt_box", _y, (txt_box._y + diff/2));
}


Any help or hints for a possible solution would be greatly appreciated.

Thanks

Problems Accessing Variables In Movie Clip Instances
I am trying to build an application that will create multiple instances of a movie clip, each with a unique width and height that will be passed from a PHP script. Each of these will be draggable and 'rotatable' on the stage. The final positions will then be recorded and saved as a jpeg on the server(through PHP). For testing locally I am just using a text file (var.txt) with the following contents...

pic_w=340&pic_h=60&ic=007

I am having problems setting the width and height of the instances using the passed variables. Below is what I have put together so far. I have an empty movie clip with the following actionscript...

onClipEvent (load) {
for (i=1; i<4; i++) {
_root.attachMovie("mainLink", "mainInst"+i, 3+i);
loadVariables("var.txt", "_root.mainInst"+i, "POST");
eval("_root.mainInst"+i)._x = 100;
eval("_root.mainInst"+i)._y = 80*i;
}
}

onClipEvent (enterFrame) {
var pic_w = parseInt(/:pic_w);
var pic_h = parseInt(/:pic_h);
for (i=1; i<4; i++) {
eval("_root.mainInst"+i).pic_w = pic_w;
eval("_root.mainInst"+i).pic_h = pic_h;
}
}


The movie clip that is called above in the attachMovie with the linkage 'mainLink' has the following actions inside of it...

this.createEmptyMovieClip("box",20);
box.moveTo(0,0);
box.lineStyle(0, 0x333333);
box.beginFill(0xCC0000, 0)
box.lineTo(100,0);
box.lineTo(100,50);
box.lineTo(0,50);
box.endFill();

// I have been trying to access the width & height variables here
setProperty("box", _width, pic_w);
setProperty("box", _height, pic_h);

box.onPress = function () {
swapDepths(15);
startDrag ("");
}
box.onRelease = function () {
stopDrag ();
}

//create some formatting for our text box
txt_format = new TextFormat();
txt_format.font = "Verdana";
txt_format.size = 12;
txt_format.color=0x000000;

//create a blank text box and set its parameters
this.createTextField("txt_box",10,0,0,0,0); // start with default values
txt_box._width = box._width;
txt_box._height = box._height;
txt_box.background = true;
txt_box.backgroundColor = 0xEEEEEE;
txt_box.variable = "ic";

txt_box._x = box._x;
txt_box._y = box._y;

//format our text box
txt_box.setNewTextFormat(txt_format);

// this is a button in the library with the linkage 'turnLink'
this.attachMovie("turnLink", "turnInst", 35);
turnInst._x = box._x + (box._width/2)-(turnInst._width/2);
turnInst._y = box._y + (box._height/2)-(turnInst._height/2);

turnInst.onRelease = function() {
swapSize(box._height, box._width);
}

swapSize = function(new_w, new_h) {
// swap the current width and height
// to give the appearance of being rotated
setProperty("txt_box", _width, new_w);
setProperty("txt_box", _height, new_h);
setProperty("box", _width, new_w);
setProperty("box", _height, new_h);

//var diff = box._width - box._height;
var diff = getProperty("box", _width) - getProperty("box",

_height);

// reset the x and y positions
setProperty("box", _x, (box._x - diff/2));
setProperty("box", _y, (box._y + diff/2));
setProperty("txt_box", _x, (txt_box._x - diff/2));
setProperty("txt_box", _y, (txt_box._y + diff/2));
}


Any help or hints for a possible solution would be greatly appreciated.

Thanks

Variables & Instances
is it possible to set two variables as clip instance?

i have to set two variables by clickin' on two buttons and to start a movie on the second click, the movie i have to start should have the sum of the two variables as instance, how can i do it?

a lil' example to explain better:
i have a clip named: white_dog
i have two buttons:
the first one set the variable var1 as white
the second one set the variable var2 as dog

is it possible, on release of the second button, to give a play action to a clip named var1_var2?

and if i have a third button (that set a variable var3) can i keep the var2 datas and give a play action to a var2_var3 movie?

thank you very much
ciao!

Instances & Variables
I know how to use both of them (sorta) and i know flash def of both but can somebody put it in more english terms where i can understand both def better???? I need to know because i finally trying to learn action script and use these a aweful lot

Please Help Variables As Instances?
Hi...I know there must be a simple way to do this but I haven't coded flash for a long time and it's driving me insane. Say I have a string variable w/ an assortment of different values, and need to use that variable when calling an instance. How's it done?

example:

_level0.sitesection = "links";
tellTarget (_root.content.subcontent.[_level0.sitesection]) {
gotoAndPlay (9);
}

In other words, I want to be telling target (_root.content.subcontent.links) to gotoAndPlay (9).
This syntax is obviously wrong, but I don't know how to do it. Can anyone help?

Thanks!

Help With Using Variables/instances
i was wondering if there was a way to make this code work:

var button = mcMovie1;

on (rollOver) {
button.gotoAndPlay("two");
}

on (rollOut) {
button.gotoAndPlay("one");
}

where "button" would be recognized as "mcMovie1", a movie instance. this way i can just copy and paste the same code over and over and not have to replace 5-10 movie instance names(whatevermovieclip.gotoAndPlay...) for all of them; instead replace one line: "var button = whatervermovieclip"

Variables To Instances
First of all, hello everyone. I haven't been here for quite some time (You last visited: 11-03-2004 at 01:35 AM ) because I betrayed flash over html/ajax. However, I want to learn to use flash again.

Anyway. I'm trying to design a simple (graphic!) shift register, to help a friend who's teaching electronics. Basically, you will have two buttons, one called "clock" and one called "data". I actually made them movie clips, since they should behave much like a checkbox.

A shift register is made of several "D latches", some electronic thing that outputs whatever is input if clock is 1. When clock is 0, it keeps the output at the last value. It's a 1 bit memory.

A shift register is made of several of these things, each with its input connected to the previous one's output. When you send a clock signal, every bit advances between them (D latch 2 gets D latch 1 conents, D3 of D2, and so on..). Due to internal propagation delays, no invalid state can be reached, so every latch will read before writing. The clock signal is sent to all of them at once.

I need to simulate this thing graphically. I designed a "D latch" movie clip, which looks like a box, with two inputs, one output, and another movieclip that displays one or zero (i use gotoAndStop to switch "states"), depending on the D latch output. A visual representation of the output, nothing more.
My algorithm is this


Code:
function updateme()
{
var myclock = MovieClip(_root.butclock)._currentframe;
var mydata = MovieClip(_root.butdata)._currentframe;
if (myclock == 2)
{
MovieClip(this.myoutput).gotoAndStop(mydata);
}
//trace("they want me to update; data = " + mydata + "; clock = " + myclock);
}

stop();
It's written in the only frame of the Dlatch. When the user clicks a button, it calls a _root.update function, which in turn will call this function on individual Dlatch instances.

What I need to do is a method to customize var myclock and var mydata for each individual D latch instance. Then, I can get one Dlatch output to read another one's input.

How can I do this the easy way - without making a movie clip for each latch? There are going to be 32 latches, so I'm not really happy about manually creating 32 movieclips.

Thanks!

Help With Using Variables/instances
i was wondering if there was a way to make this code work:

var button = mcMovie1;

on (rollOver) {
button.gotoAndPlay("two");
}

on (rollOut) {
button.gotoAndPlay("one");
}

where "button" would be recognized as "mcMovie1", a movie instance. this way i can just copy and paste the same code over and over and not have to replace 5-10 movie instance names(whatevermovieclip.gotoAndPlay...) for all of them; instead replace one line: "var button = whatervermovieclip"

Syntax For Instances As Variables?
hello, again. thanks for the help, musicman and bace, much appreciated.

now i have another question. here's dot syntax for targeting an instance of a movie clip within another movie clip:

_root.containone.one
_root.containtwo.two


What i'd like to have is both instances as variables, based on the mode i'm in...


_root[contain add mode][mode]<<didn't work



i'm thinking that making both the container and clip(s) to be duplicated both variables would make it a lot easier to manage the overall movie.

the duplicated clip contained in another clip for reasons of controlling its depth would now have the instance name of the mode that refers to it, as in

i'm in mode one, so mode == one, so i would state the instance of the clip to be duplicated as 'one'

mode two would direct to an instance called 'two'

the containers would have instances named
'containone' and 'containtwo' and i could refer to them as 'contain add mode' and depending on what mode i'm in, the returned values would be correct.

The Question:

What is the proper dot syntax to target these instances.


I've tried:
_root[contain add mode][mode]
_root.contain[2][mode]

well, pretty much every variation i could think of, except of course the correct way...




any ideas?

thanks for any assistance.

Multiple Instances And Variables Big Q
OK
my menu has an arrow follower on rollover
everything ok

I want that when i press a button the arrow does an animation and opens up the information under the menu

(i put only a rotation for the MAIN button - as an example-)
my problem

i want that the arrow state to be detected by the other buttons

if it's already open and if i press another button i want it to close and then move to emphasize the next button ( doing teh animation backwards)

so how can i make that the buttons detect the state of the arrow??????

Inputs any any kind of suggetsion appreciated

thanks in advance

Reaching Instances With Variables
hi folks

I want to reach a movie clip using variables, when I have a mc in the same timeline I do this:


variable = 1;
this["menu_"+variable].gotoAndStop(1);


it works fine.
the problem comes when im not in the same timeline, I tryed to do something like this, but it didnt work:


variable = 1;
mc_test.this["menu_"+variable].gotoAndStop(1);

it shows me the following error message:"Expected a field name after '.' operator."

have anyone make the thing work??

Thanks!!

Mike

Help: Calling Instances By Variables
Hi...I know there must be a simple way to do this but I haven't coded flash for a long time and it's driving me insane. Say I have a string variable w/ an assortment of different values, and need to use that variable when calling an instance. How's it done?

example:

_level0.sitesection = "links";
tellTarget (_root.content.subcontent.[_level0.sitesection]) {
gotoAndPlay (9);
}

This syntax is obviously wrong, but I don't know how to do it. Can anyone help?

Thanks!

Help With Adding Variables/instances
Alright, on my website www.fatbug.com I have an order form, the user can pick between how many labels they want, and what type of shipping using a combo box. What im trying to do is have a dynamic text box display the total purchase i.e. $575 for 5000 labels and 25 for priority shipping.

Here is the .fla and i hope to hear back!

http://www.yousendit.com/transfer.ph...774319571CB7C7

Using Variables To Call Instances
I wish to be able to use a defined variable to call other movie clips.

For instance,

//I wish to take the following location and set it to a variable...

varinstance=_root.MC1

//Set the name of the variable I wish to access

varaddress=firstname

//and trace the firstname variable from the _root.MC1 (so for instance _root.MC1.firstname)

trace(varinstance.varaddress)

// And assume that _root.MC1 has the variable firstname with the value of "Michael"


But this does not work and returns undefined.

I have also tryed the combinations of;
varinstancevaraddress
varinstance+varaddress
varinstance+"."+varaddress

but all do not return the value located in the variable _root.MC1.firstname.





My question is how can I accomplish using a variable to use in a path to a variable/movie clip/etc



thanks for your time

Using Variables To Call Instances
I wish to be able to use a defined variable to call other movie clips.

For instance,

//I wish to take the following location and set it to a variable...

varinstance=_root.MC1

//Set the name of the variable I wish to access

varaddress=firstname

//and trace the firstname variable from the _root.MC1 (so for instance _root.MC1.firstname)

trace(varinstance.varaddress)

// And assume that _root.MC1 has the variable firstname with the value of "Michael"


But this does not work and returns undefined.

I have also tryed the combinations of;
varinstancevaraddress
varinstance+varaddress
varinstance+"."+varaddress

but all do not return the value located in the variable _root.MC1.firstname.





My question is how can I accomplish using a variable to use in a path to a variable/movie clip/etc



thanks for your time

Targeting Instances With Variables
So i have a global variable 'selected' for the page currently selected which has the value 'solo' assigned to it when the movie plays.

this is on frame 1 of the main timeline..
var select = "solo";

Then i have a movie clip (content movie) which holds all the different pages and in this are the buttons which when clicked i want to use the variable to move the playhead of the movie corresponding to the 'selected' variable.

This is the actionscript which is on the first frame of the content movie..

button.onRelease = function() {
this[selected].gotoAndPlay(2);
this[selected].alpha(5, 0);
solotab.gotoAndPlay(2);
solotab.alpha(5, 60);
};

the movie which should be being targetted is on the same timeline as this script..

the movie 'solotab' gets targetted fine but i can't get the movie targetted with the variable to work..

what am i doing wrong?

thanks for any help

Si

Instances Sharing Variables?
I'm having a problem with my code whereby when a new instance of BallMovie is created all of the BallMovies move together instead of being independant. Now I imagine that this is because they are all sharing variables and every time Bounce() is called on each instance it is using the "old" variables of the previous instance. I thought creating each new instance was supposed to have totally seperate variables unless they were defined as static?
Any suggestions?

Main code Frame 1:

Code:
import BallClass;
var gravity:Number = 1;
var restitution:Number = 0.6;
var friction:Number = 0.9;
var balls:Array = new Array();
var x:Number = 0;
var delay:Number = 0;
var noOfBalls:Number = 0;
Object.registerClass("BallMovie", BallClass);
Main code Frame 2:

Code:
if (!delay) {
delay = 120;
x++;
_root.attachMovie("BallMovie", "Ball"+x, x+100);
this["Ball"+x].RandomPosition();
balls.push("Ball"+x);
} else {
delay--;
}
for (i in balls) {
this[balls[i]].Bounce();
}
Main code Frame 3:

Code:
gotoAndPlay(2);
BallClass.cs

Code:
class BallClass extends MovieClip {
//declare variables.
private var vel:Object = {x:0, y:0};
private var pos:Object = {x:0, y:0};
private var old:Object = {x:0, y:0};
private var radius:Number;
private var dragging:Boolean = false;
//declare other variables on instance creation.
function BallClass() {
this.radius = (this._width/2);
this.pos.x = this._x;
this.pos.y = this._y;
this.old.x = this._x;
this.old.y = this._y;
}
//move the ball to a random position
function RandomPosition() {
this.pos.x = (Math.random()*(Stage.height-(2*radius)))+radius;
this.pos.y = (Math.random()*(Stage.width-(2*radius)))+radius;
this.old.x = this.pos.x;
this.old.y = this.pos.y;
this._x = this.pos.x;
this._y = this.pos.y;
}
function Bounce() {
if (!this.dragging) {
this.vel.y += _root.gravity;
this.pos.x += this.vel.x;
this.pos.y += this.vel.y;
if (this.pos.y+this.radius>Stage.height) {
this.pos.y = Stage.height-this.radius;
this.vel.y *= -_root.restitution;
this.vel.x *= _root.friction;
}
if (this.pos.x+this.radius>Stage.width) {
this.pos.x = Stage.width-this.radius;
this.vel.x *= -_root.restitution;
}
if (this.pos.x<this.radius) {
this.pos.x = this.radius;
this.vel.x *= -_root.restitution;
}
this._x = this.pos.x;
this._y = this.pos.y;
} else {
old.x = pos.x;
old.y = pos.y;
pos.x = this._x;
pos.y = this._y;
vel.x = (pos.x-old.x)/2;
vel.y = (pos.y-old.y)/2;
}
}
}

How Do I Adress Instances By Variables ?
Hello.
I'm sitting here stuck with a Flash Mx dilemma:

How can I use a object instance with a name stored in a variable ? Im going to run hittests on two arrays containg the names of objects I want to check for collision, but I can't get this to work.. so please help me if you can.

Ok. To make it clearer, this is kinda the script I did:

for (i=1;i<10;i++){
ObjName1="_root.PLANE"+i;
ObjName2="_root.ROCKET"+i;

Here I wanna check if they collide... can this be done in any way by using String information ? I know THIS code can be solved in other ways...

if (ObjName1.hitTest(ObjName2)){
ObjName1.gotoAndPlay(20);//Play crashanim;
}
}

Thanks for any help.

/ Kae

Global Variables To Instances?
hi guys, i made this animation movieclip, test_mc. that has a button on it and i'm using 3 different instances of it.
I've named each instance for example, oneI, twoI, threeI.

what i want is for when a frame 15 is passed over in the animation, something on the main scene to occur.

Now I'm using a global variable in the movieclip and im checking if it's true or false on the main stage.

however, clicking on a button on the instance makes the global variable true, and when it is true i want the effects to occur on the instance i just clicked on, however, it happens for all 3 instances.

any ideas?

Using Variables As MovieClip Instances
I'm having some trouble trying to duplicate movieclips randomly. I have created an array with the instance names of the MCs i have on stage. Then I'm trying to create a variable that selects one random element from the array. Finally I want to use that variable as a target to duplicate my movie Clips... but it doesn't work.


Here is the code:


Code:

var Items = new Array('bombon', 'regalo', 'corazon');

pos = new Object();
pos._x=random(550);

i=0

function randomize (){
targeta=Items[random(3)]
targeta.duplicateMovieClip("item"+i,i,pos);
i++;
}

var Int = setInterval(randomize, 10);

Variables And Movieclip Instances
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:
CODEvar msgText = "";
this.onRollOver = function() {
  trace(this.msgText);
};

Variables And Instances Linked?
I'm don't do a whole lot of advanced coding so please bear with me.

I've got a lot map of a community with lot numbers. They are all weird sizes so I went and traced every one, filled them in with black and made each a movie clip and gave it an instance name of lot-11, lot-12, lot-13, etc...

I have a text file that is generated from a back end that tells whether a lot is available. For example, each lot # that is sold is marked with a zero like "lot-11=0&lot-12=0&lot-13=0"

Basically I want the blocks to go to the second frame of the clip if the variable = 0, so lots 11, 12, and 13 would show all be on frame 2. On each clip I have this code:


ActionScript Code:
onClipEvent (load) {
    if (lot-12 < 1) {
        gotoAndStop(2);
    }
}


Is there a way I can just import the text field and write some kind of dynamic "if" function that will cross reference the instance names with the variables? There are hundreds of lots. I appreciate any help, I've looked for hours for examples.

Calling Instances With Variables
I am getting information from a database and puting the text into text fields inside of a movie clip. Since I don't know before hand how many I will have I am using the attachMovie method inside of a for loop. I am giving the movie an instance name with a variable; however I am then having trouble assigning values to that instance name because if I use the variable it will look for a instance with the name of that variable instead of the value of it.

recieveVars.onLoad = function (success) {
number = recieveVars.number;
var myPosts:Array = new Array(number);
for(i=0; i<number; i++){
main["subject"+i] = this["subject"+i];
main["message"+i] = this["message"+i];
myPosts[i] = "posts" + i;

_root.attachMovie("mc_posts", myPosts[i], 10);
_root.myPosts[i].subject_txt.text=main["subject"+i];
_root.myPosts[i].message_txt.text=main["message"+i];

}

}



As you can see, I tried using arrays to solve this problem but with still no luck. If anyone can help, I would appriciate. Thanks in advance, Adam

Help With Adding Variables/instances
Alright, on my website http://www.fatbug.com I have an order form, the user can pick between how many labels they want, and what type of shipping using a combo box. What im trying to do is have a dynamic text box display the total purchase i.e. $575 for 5000 labels and 25 for priority shipping.

Here is the .fla and i hope to hear back!

http://www.yousendit.com/transfer.php?action=download&ufid=93774319571CB7C7

Variables And Multiple Instances Of Same Clip
So I've got a clip (let's call it joeClip) that has a variable in it (let's say joeNumber)...

I want to be able to set joeNumber differently in each instance...so I create three instances by names of joeClip1...joeClip3

if I say
_root.joeClip1.joeNumber = 1;
_root.joeClip2.joeNumber = 2;
_root.joeClip3.joeNumber = 3;

It just blanks out the value on those clips...second time this has happened...I ended up with a different design the first...this time I want to figure it out. Any ideas?

Then I want to deal with the clip dynamically too...

_root.[clipVarReference].joeNumber = someValue;

Thanks in Advance,

Galego

Listing Variables Attached To Instances
Is there a way to list all of the variables attached to an instance, both name and value?

ie. I have an instance of fido of the class Dog. I'd like to know all of the class specific variables and values plus anything that is specific to fido.

Is this possible?

Easy Question About Variables And Instances
Okay... I haven't worked in flash in quite some time, and for some reason this is not coming back to me... I have some buttons I want to set properties for... However, I'd like to be able to grab the same code and put it into each button to save time. How do I tell the coding for the button to set, say, _alpha for the instance executing the code, rather than referencing the instance specifically? I thought you just used

_self._alpha = 0;

however, this seems to set the alpha for the entire scene, not the button itself.

for the button instance "blaze", this works:

blaze._alpha = 0;

but I want this to be generic enough to use on any button without manually changing the instance name each time.

What am I having such a hard time remembering? Sorry for wasting people's time...

Variables Scope Within MovieClip Instances
Hi guys.

I found something interesting when playing with variables that doesn't make much sense for me, I understand that's the way it works and period but I would like someone explain to me why, I am one of those that needs to know way things works in a certain way to better understand it.

It's about the scope of variables, if in a function a declare a variable, that variable lives only within the scope of that function, once the function isn't running, the variable dies.

If I declare a variable externally to the function, the variable lives within that script being available for all functions within that script.

Following this logics, the following shouldn't work, but it does, within a MovieClip...


PHP Code:



onClipEvent (load) {
    var aVariable:Number = 2;
}
onClipEvent (mouseUp) {
    trace(aVariable);





For me it doesn't make much sense accessing variables from a piece of code that looks like is encapsulating its variables, I don't know how to explain this, I hope you understand what I mean.

Is there a logical explanation for this or it's one of those things that comes from the pass and we have to live with it?

Thanks guys.

Text Fields, Instances Or Variables
Hello,
I've received some conflicting information about how text fields should be referred to and I'd really like to clear it up. One place I read that you should always use the var field in the text field properties panel to give your text field a variable name, and you shouldn't use the instance name field. Someone else told me exactly the opposite saying the var on the text field properties panel was left over from Flash 5 and it shouldn't be used.

I built a gui with calculator type buttons that filled an input text field. I gave the text field a var name and not an instance name. They worked fine. I've now found something to incorporate in the gui, but it was originally built with text fields with instance names not variable names. When I try to adapt either my gui or the new code one or the other doesn't work, they work fine separately.

I would really appreciate any clarification you could offer.
thank you,
Beatie

Making Instances And Assigning Variables
Hi.
Sorry to ask so many questions but;
I made a sprite, simple enough. Now I want to give the sprite 2 variables and I can't figure how to do it!
My sprite is essentially a button, with a shape and textfield instances inside it. I have got an eventListener to check if the mouse is over. If it is, it calls a function which makes another eventListener Event.ENTER_FRAME on the sprite instance to animate the shape instance inside it. But for the animation to work I need these two variables to be given to the sprite instance. But when I try to do somthing like this;

Code:
var p = buttonCreate("cool",100,10,5);
addChild(p);
function buttonCreate(txtT,wT,hT,extT) {
var a = new Sprite();
a.curExt = 0;
a.maxExt = extT;
var b = new Shape();
a.addChild(b);
var t = new TextField();
a.addChild(t);
a.addEventListener(MouseEvent.MOUSE_OVER,buttonOver);
return a;
}
It doesnt want to give it the curExt or maxExt variables. I understand that you have to make a variable with the var keywork in AS3 before it works but how do you do it externally from the instance itself?
Thanks for reading/helping,
Dan

Also how should I store an identifier to the shape instance on the sprite? Because for the animation to work I am going to need to reference to it...

Controling Variables For Spawnable Instances Of Movieclips
I am trying to make a flash application that has spawnable window like objects that contain dynamic text pulled from \folderinfo.txt

1.) How do I spawn/kill an instance of this movieclip on a click of a button?
2.) How do I change the variables contained in that spawned instance of the moviecliop?
3.) If I have more than one of these instances open, how do I distinguish between them?

[MX04] Getting Variables Of Instances In Main Clip
I have a instance of boxButton called box1

and in box1, i have:

boxen = 1;

so to get the instance box1's varaible boxen in the main timeline, i should use

answer = _level0.box1.boxen;

right? however this returns undefined.. from tracing it

is there any answer to this?

thanks.. i tried to be as clear as i could

Private Component Variables Share Across Instances
Hey all,

I'm having a problem that's really driving my crazy here. I have a component with an array defined in it's class file as private. Somehow, when I have more than one instance of the component, all instances seem to share the same array... If I modify the array in one of the instances, it's modified elsewhere in the other instances.

At this point, I can't really show any of the actual AS since what I'm working on is a for work, but what I'm wondering is:

1. Has anyone run into similar problems before?
2. Is there a way to define variables within classes / component classes that will ensure that this doesn't happen?

Thanks very much in advance,

-sp

[Help] Noob Question...manipulate Variables From Different Instances...
Hello~!I'm new here and I am self-learning flash...
I don't know if I can describe this situation very clearly because I'm poor at English...

Here's the problem:
I suppose this action is on the frame:

Quote:




var money1:Number = 5000




and this is on the button's action:

Quote:




on(release){
money1-=100
}




What i want to do is when i click the button, the variable money1 (frame's action) will decrease by 100. Since these actions are on different platform, how do i change the variable money1 from the button's action?
The highlighted statement is absolutely wrong, but still i have to show this problem i faced.

oh btw, I know that these can be solved by using button.onRelease on frame's action, but I wanna learn how to manipulate variables from different symbol or instance...so, can anyone help me? I'll be very grateful...

Variables And Instances And Movei Clips Rotting My Brain
Bit of a tricky one, this.

I have loads of movie clips - over 100. Well, it is one, copied and pasted 100 times, to keep file size down. Each one has a different instance name (1, 2, 3, 4 etc) and in the main timeline there are over 100 text boxes with corresponsing names (1, 2, 3, 4 etc).

In these movie clips, depending on what frame each one is at, it puts a different variable into its corresponding text box, e.g. "house", "factory", "shop" etc. There are about 20-25 of these variables.

The actionscript which does this is:


Code:
Set Variable: "_level0:"&_name = /:status


Which basically says, find the text box in the main timeline with the same name as the hosts movie clip instance name, and enter the contents of the text box "status" (which is in the main timeline).

Ok, that's the background sorted.

This method works. Hurrah. But I now need it to work kind of in reverse. With me? Ok, stay with me on this one...!

I have a movie, very similar to the above one, but instead of creating the variables (which are then passed to a database using ASP), variables are entered INTO it using the ASP and database. I can do that, but the Flash is not liking it. Well, it is, but it's not doing what it should!

These 100 or so text boxes in the main timeline become populated by data passed into them from the database. I want the data in these (e.g. "house" "shop" etc) to make the movie clip with the same name go to the frame with the same name as that data.

For example, say for movie clip number 35. Data is passed into the text box called "35". Let's say this data was the word "house". In movie clip 35 there would be some actionscipt, not dissimilar to the above, which reads the data from this text box, and goes the frame. So, it would see that the word "house" was there, and so would go to and stop the frame named "house" within that movie clip.

I have tried putting this in the Movie Clip:


Code:
Go to and Stop ("_level0:"&_name)


But it doesn't seem to work. Any ideas??

I'm passing data into the movie by attaching it to the URL of the movie. So, for the above example, the HTML page would embed the movie with the URL

movie.swf?35=house etc

Get me drift? Good!

I know it's a long explanation but it's a bit of a tricky one to sort out. Pleeeease, any help! I'm pretty much desparate now - this is basically my last hope.

Thanks,

Nick

Calling Movieclip And Option Button Instances Using Variables
Hi,

I use flash mx 2004.

My problem is this:

I am loading an xml file into flash which contains information on the contents of the movie.

One piece of info is contained in the attribute of an xml tag. I am trying to set the value of this attribute as the instance name which references an object in the movie.

let me give you an example;

I have a question with four option buttons each with an instance name of option1, option2, option3, option4. The xml file not only loads the questions but also contains a reference, as an attribute, which indicates the correct answer.

I have no problems extracting this value - which for example we can say is equal to "option3", but I can't seem to get it to work.

option3.selected == true; would be the way to hard code this but how do I get it to use the value I extract from the xml file.

valuefromXML.selected == true;

this would also apply to referencing an instance of a movieclip.

movieclipnamefromXML.play();

I hope this has been explained clearly!!??

Thanks in advance

T.

Help In Passing Variables To Instances Of A Dynamic Text Movieclip
I have constructed a function that returns the square footages of the Living, Garage and Lanai for a specific home designs.
--------------------------------------------------------------
function getDimensions(i:Number):Void {

//Inside the function, arrays are prepopulated for 40 different home designs - eg:

//Martinique Design
aLiving[1]="1,657";
aLanai[1]="203";
aGarage[1]="494";
aTotal[1]="2,354";

//Barbados Design
aLiving[2]="2,040";
aLanai[2]="243";
//etc..
// Followed by code to structure and load the selected array into dynamic text variables
}
----------------------------------------------------------------
the statement:
getDimensions(2);
successfully populates a preformatted, dynamic text layout table on the main timeline with the Barbados design values. The text holder layout table was manually created.

I then moved the text holder table into a separate movieclip and dragged two instances of that MC onto the main timeline, named each instance (e.g. mcDim1 and mcDim2). The function code was left on the main timeline.

What I can't figure out next is how to use my function to populate each instance by passing the home design number (the array key) as before.

I tried things like this.mcDim1.getDimensions(2); but so far I can't get anything to work and have been unable to find the correct syntax in the extensive reference material I have.

Would much appreciate any help.

Placing Array Values Into Variables To Control Instances
Hi there, I am having some troubles with pulling some values out of an array into a variable and then using that variable to control an Instance value assigned to a set of buttons.

Frame 1 (scene 1) Actionscript

ActionScript Code:
gMarray=new Array();gMarray[0] = 4; gMarray[1] = 1; gMarray[2] = 1; gMarray[3] = 1; gMenuListarray=new Array();gMenuListarray[0] = "gbLaw";gMenuListarray[1] = "gbPrev";gMenuListarray[2] = "gbPower";gMenuListarray[3] = "gbHandle";


Frame 1 (scene 2) Actionscript

ActionScript Code:
for(i=0; i<=3; i++){ //if i is 3 or less do...    var gTemp1=gMarray[i];    trace(gTemp1);  // display the value held    for(j=1; j<=4; j++){ //if j is 4 or less do...        var gTemp2=(gMenuListarray[i]+j);        trace(gTemp2);        if(gTemp1 == j){ //check and see if the variable in a gM# is equal to j            gTemp2._visible=1;        }else{            gTemp2._visible=0;        }    }}


gMarray is being used to hold a value (for tracking).
gMenuListarray is being used to hold the names of the button instances.

As the script goes through the for loops it adds j to the value of whatever is in gMenuListarray item i (ie. gbLaw1, gbLaw2, etc.) then it checks if the value of gMarray is equal to j, if it is equal it makes the instance name that equals the combined value of gMenuListarray (array item plus j appended to it) visible or invisible on the stage. The problem is that Flash MX 2004 seems to be incapable of reading using this combined value to find and modify the instance, it goes into the loop, compares and then exits out without doing anything. I have check my logic using a trace command to tell me "true" or "false" and that works correctly and I have double checked to ensure that the combined value of gMenuListarray+j equals an Instance name asigned to a button on my stage.

Thoughts? Comments? Suggestions? A hammer to beat this software into submission?

Placing Array Values Into Variables To Control Instances
Hi there, I am having some troubles with pulling some values out of an array into a variable and then using that variable to control an Instance value assigned to a set of buttons.

Frame 1 (scene 1) Actionscript

ActionScript Code:
gMarray=new Array();gMarray[0] = 4; gMarray[1] = 1; gMarray[2] = 1; gMarray[3] = 1; gMenuListarray=new Array();gMenuListarray[0] = "gbLaw";gMenuListarray[1] = "gbPrev";gMenuListarray[2] = "gbPower";gMenuListarray[3] = "gbHandle";


Frame 1 (scene 2) Actionscript

ActionScript Code:
for(i=0; i<=3; i++){ //if i is 3 or less do...    var gTemp1=gMarray[i];    trace(gTemp1);  // display the value held    for(j=1; j<=4; j++){ //if j is 4 or less do...        var gTemp2=(gMenuListarray[i]+j);        trace(gTemp2);        if(gTemp1 == j){ //check and see if the variable in a gM# is equal to j            gTemp2._visible=1;        }else{            gTemp2._visible=0;        }    }}


gMarray is being used to hold a value (for tracking).
gMenuListarray is being used to hold the names of the button instances.

As the script goes through the for loops it adds j to the value of whatever is in gMenuListarray item i (ie. gbLaw1, gbLaw2, etc.) then it checks if the value of gMarray is equal to j, if it is equal it makes the instance name that equals the combined value of gMenuListarray (array item plus j appended to it) visible or invisible on the stage. The problem is that Flash MX 2004 seems to be incapable of reading using this combined value to find and modify the instance, it goes into the loop, compares and then exits out without doing anything. I have check my logic using a trace command to tell me "true" or "false" and that works correctly and I have double checked to ensure that the combined value of gMenuListarray+j equals an Instance name asigned to a button on my stage.

Thoughts? Comments? Suggestions? A hammer to beat this software into submission?

Variables In Moviclip Instances Passed To Cgi Script With Rest Of Form
I have a flash form with lots of elements with declared variables on the main timeline. In the same form I have checkboxes that are movieclips which set additional variables depending on what fram the movieclip instance is on. When I submit the form only the variables on the movies main timeline get sent to the cgi script and mailed to me. How do I send the variables set in the individual movieclips as well so they go with the rest of the form?

Instance Variables In Objects Retain Values From Previously Created Instances
this makes no f-ing sense and I want to cry.

I have a class called Note, it receives some text, makes a movie clip makes a textfield on the clip and shows it.

Each instance can receive text any number of times and itll keep the text in an array and when it comes time to show the note, it arranges the text fields in line under each other.

the array that holds the text is an instance variable. Now, when I have 2 or more notes in the same movie, the array for each instance RETAINS the text from the previous notes! WTF.

I do not at any time insert the previous notes' text into the current note, nor is the text array static, those would be the only two logical explanations, nor are the variables of the two notes the same when I create them in the movie.

here's code

[CODE]
//creation of the first note on frame 37 of the movie
var noteNote:Note = new Note(this, _root.movie, 650, 50);
noteNote.addText("<b>Securities</b>Source provides online access to the most sought-after Canadian and U.S. securities law materials – all in one place – through a single password.");
noteNote.drawNote();
noteNote.show();
[/CODE]

[CODE]
//creation of the second note on frame 73 of the movie
var noteNote2:Note = new Note(this, _root.movie, 650, note.y + note._height);
noteNote2.addText("As the official publisher, Thomson Carswell’s OSC Bulletin is available weekly by noon each Friday and contains the full weekly Insider Reporting data (Chapter 7) directly from CDS.");
noteNote2.drawNote();
noteNote2.show();
[/CODE]

[CODE]
public var note:MovieClip;
public var movie:Movie;
public var x:Number;
public var y:Number;
public var parent:MovieClip;
public var parentMovie:Movie;
public var fadeDir:Number = 0;
public var fadeSpeed:Number = 8;
public static var width:Number = 260;
private var texts:Array = new Array(); //THIS IS THE ARRAY FOR THE TEXT BLURBS
public static var buffer:Number = 15;
public static var color:Number = 0xf9de80;
public var _height:Number;

...

///text should be one paragraph or one point
///if isPoint is left undefined it is assumed false
public function addText(text:String, isPoint:Boolean):Void
{
texts = new Array();
isPoint = isPoint == undefined ? false : true;
var index:Number = texts.length;
texts[index] = [];
texts[index][1] = isPoint;
//
//var textParent:MovieClip = note.createEmptyMovieClip("text_parent_" + note.getNextHighestDepth(), note.getNextHighestDepth());
var tf:TextField = note.createTextField("text_" + note.getNextHighestDepth(), note.getNextHighestDepth(), buffer, 0, width - ((buffer * 2)), 1000);
tf.wordWrap = true;
tf.multiline = true;
//tf.embedFonts = true;
//tf.setTextFormat(makeFormat(isPoint));
tf.background = true;
tf.backgroundColor = 0xffffff;
tf.html = true;
tf.type = "dynamic";
tf.htmlText = text;
tf.autoSize = true;
tf._visible = false;
texts[index][0] = tf;
var f:Array = texts;
}
[/CODE]
I set f to texts every time text is added so I can see texts as a local in the debugger, this is how I found out that the array still kept the text from the Note on frame 37 when making the note on frame 73.

I've solved this by clearing the array before I first use it in a note, but this still makes no sense, that instance variables are retaining the values of previous instances.

I'd like some input on what this could be.

Movie Control Stop/movie Instances
I'm trying to run a movie which has a movie clip within it. I've stopped the main timeline once the instance of the movie clip is reached, but that movie clip won't continue to play!? This only happens when this is the second scene of a movie... it's all fine when it's on its own scene.

Can anyone help me with this problem??

THanks
Stephen.

Movie Instances
hi,

i'm trying to achieve an effect where 5 orbs come from different directions to meet in the center.
So far, the method i used was to create a movie Clip of a ball floating in (along a motion path) which was fine. Then i want to have 4 more copies, but each from a different direction. I just made 4 new movie clips and rotated the path and changed where the ball started.

However this is inefficient so i was just wondering, how do i edit a movie clip instance without the original from the library being changed? if i can't, what's the best way to do it...

thx
Stuart

How To Hide Movie Instances
I have 2 movie clips: A & B. They each have an invisible button.

I want to, on the main timeline, only show A when it starts. When the user clicks on A, hide movie instance A and show movie instance B (and vice versa, click on B, show A/hide B).

I tried using the _visible, but it doesn't seem to be working. Maybe I'm putting code in the wrong place.

Help!
Ya Tin

Looping Through Movie Instances ?
I have an image, which I have broken up into 100 movies. I have named them square1 to square100. I'm trying to programmatically make each one appear by setting the visibility property to true using a loop.

Does anyone know how I can substitute the var i in the command below so that it is read as a movie instance...

----------------------------------------------
for (var i=1;i<=100;i++){
_root.logo.square+i._visible = true;

}
----------------------------------------------

Attaching A Movie...and Instances
When I attach a movie using a loop,that has another movieclip under it testing for on press and trace(this); after the name is instance 1,the next time it is instance 34,instance 67 etc..how do I get rid of that ?
I'm testing for information using this.something and assign it when the movie is attached, that is why I want to get rid of it...

Thanks

Playing Movie Instances
Hi.
Im fairly new to ActionScripting and am using Flash MX. I have several instances of a single movie. I want to play them in a cascading way so they play all at slightly different times(not sure how to do that yet, but thats not the point). Most importantly I want the clips to play in a random order. So ifyou start the movie over again the clips wont play again in the same order. Do i have to enter all the instances into an array and then randomly call entries of the array? Is this even possible?

thank you

will

Copyright © 2005-08 www.BigResource.com, All rights reserved