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




How Do You Set A Variable Within A Movieclip?



Got a movieclip by name of textbox with variable name position..

How do you set the variable within the mainstage?

I've tried...

textbox.position = 15;
_root.textbox.position = 15;


please help me!

Thanks,
louis



ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 03-06-2006, 05:18 PM


View Complete Forum Thread with Replies

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

Loading Variable Smarclip Into Variable Movieclip?
HO HO HO FashMonsters-

Damn, Loading a variable driven smartclip into a movie clip can be a lil' tricky. Problem is I think I need the movie clip to be a variable as well. My button action is calling up my movie clip instances which are referencing the variable smart clip. However, each button action loads a new movie clip atop the previous. I either need to remove the previous movieclip or make the movie clip a variable loading variable smart clips.

Da Dizawg wud LUV some Hizelp!

Change String Variable To A MovieClip Variable
Hi

I have been banging my head against a brick wall regarding the following problem which must be very simple to fix, just can't see the answer.

I have a class assigned to a movieclip called canvas. The class is called drawClass. I have called the instance of canvas on the stage 'drawingCanvas'.

When I trace "drawingCanvas" I get

[object drawClass]

which is fine. Tracing drawingCanvas.name gets me the instance name

'drawingCanvas'.

This is a String variable.

Basically what I am trying to do is pass the MovieClip name to another class. In my example the class 'toolBar', which can then interact with the MovieClip.

The problem is passing 'drawingCanvas.name' results in a String, so I get an error saying :

TypeError: Error #1034: Type Coercion failed: cannot convert "canvasArea" to flash.display.MovieClip.

I can't for love or money find a way to convert a String variable to a MovieClip variable! I have the name of the MovieClip, I just need to tell the toolbar class. But I can't find a way of doing this as the instance on stage is an object of drawingClass, not a MovieClip (unless MovieClips with attached classes are not treated as standard MovieClips?).

Any ideas are most welcome. I'm sure I am missing something obvious.

Thanks for looking

Convert String Variable Into Movieclip Variable?
I have a variable called something like city_str which has a value of "toronto". I also have a moveclip (exported for AS) called toronto_mc.

What I want is a way of concatenating strings of "toronto" and "_mc" and assigning it to a movieclip variable called toronto_mc. Everything I try gives me a mismatch error in the compiler. I'm writing AS2 using Flash CS3. Any ideas?

MovieClip With Variable...
I have problems with a mc that has a variable loaded into it. It works fine but when I try to tween the alpha-value of the clip (in order to make a fade-in effect) it doesn´t work! I tried to tween the brightness-value and...no problem! The thing is I´m having this clip on a picture so I really wan´t to get to the alpha-value, otherwise I+ll have to forget the fade-effect:-(
Is this a known bug or is it supposed to be this way?? I mean - if the brightness-value is reachable, why not the alpha?!?

/confused flash 5-tester...

[F8] Can't Get A Variable Value From A Movieclip
I have a movieclip with this script attached to it.


Code:
onClipEvent (enterFrame) {
if (this.hitTest(_root.mv_targetgrid.target1_mc.fencetargetsoldiers_mv)) {
this.gotoAndStop(2);
_global.hGlobal == "true";

} else if (this.hitTest(_root.mv_targetgrid.target2_mc.cannon_targets_mv)) {
this.gotoAndStop(2);
_global.hGlobal == "true";

} else if (this.hitTest(_root.mv_targetgrid.target3_mc.tent_targets_mv)) {
this.gotoAndStop(2);
_global.hGlobal == "true";

} else {
this.gotoAndStop(1);
_global.hGlobal == "false";

}
}
The script performs perfect. But the "_global.hGlobal" value is not being read by this script that is in the main timeline


Code:
_root.btn_fire.onPress = function() {
if (_global.tGlobal == "target1" && _global.aGlobal == "ammo1" && _global.fGlobal == "nofuse" && _global.hGlobal == "true"){
_root.mv_targetgrid.target1_mc.fencetargetsoldiers_mv.gotoAndStop(2)
} else {
_root.mv_targetgrid.target1_mc.fencetargetsoldiers_mv.gotoAndStop(3)
};

if (_global.tGlobal == "target2" && _global.aGlobal == "ammo2" && _global.fGlobal == "fuse" && _global.hGlobal == "true"){
_root.mv_targetgrid.target2_mc.cannon_targets_mv.gotoAndStop(2)
} else {
_root.mv_targetgrid.target2_mc.cannon_targets_mv.gotoAndStop(3)
};

if (_global.tGlobal == "target3" && _global.aGlobal == "ammo3" && _global.fGlobal == "fuse" && _global.hGlobal == "true"){
_root.mv_targetgrid.target3_mc.tent_targets_mv.gotoAndStop(2)
} else {
_root.mv_targetgrid.target3_mc.tent_targets_mv.gotoAndStop(3)
};
_root.mv_gamecannon.gotoAndPlay(2);
};
any idea how I get around this problem?

MovieClip Variable
In a MovieClip named testMC, there is a function,

loadCodes();
function loadCodes() {

this.col = _root.DropZone;
this.ast = _root.temp;
this.col.tmp3 = 0;

...


But I can not find the place where the col, ast, and tmp3 are defined.

Are the col, ast, tmp3 created at run time or they are the implicit attributes
, no need to explicitly define. If so, what are the "col", "ast", and "tmp3"?


Thanks

Scott

MovieClip Name In Variable?
Hi all,

I want to give the variable 'mctarget' the value of a movieclip instance that I want to play. I have a button with this code:


Code:
on (release) {
mctarget = "webdesignmovie";
this.gotoAndPlay(15);
}
'this.gotoAndPlay(15);' starts the fade-out of the current movieclip, and on the last frame of this current movieclip I have:


Code:
stop();
this._visible=false;
_parent.mctarget._visible=true;
_parent.mctarget.gotoAndPlay(2);
For some reason, the mctarget movieclip (webdesignmovie) does not become visible nor play. When I change mctarget._visible to webdesignmovie._visible, it does work.

Any ideas why the variable doesn't work in the _visible command?

Can't Get A Variable Value From A Movieclip
I have a movieclip with this script attached to it.


Code:
onClipEvent (enterFrame) {
if (this.hitTest(_root.mv_targetgrid.target1_mc.fencetargetsoldiers_mv)) {
this.gotoAndStop(2);
_global.hGlobal == "true";

} else if (this.hitTest(_root.mv_targetgrid.target2_mc.cannon_targets_mv)) {
this.gotoAndStop(2);
_global.hGlobal == "true";

} else if (this.hitTest(_root.mv_targetgrid.target3_mc.tent_targets_mv)) {
this.gotoAndStop(2);
_global.hGlobal == "true";

} else {
this.gotoAndStop(1);
_global.hGlobal == "false";

}
}
The script performs perfect. But the "_global.hGlobal" value is not being read by this script that is in the main timeline


Code:
_root.btn_fire.onPress = function() {
if (_global.tGlobal == "target1" && _global.aGlobal == "ammo1" && _global.fGlobal == "nofuse" && _global.hGlobal == "true"){
_root.mv_targetgrid.target1_mc.fencetargetsoldiers_mv.gotoAndStop(2)
} else {
_root.mv_targetgrid.target1_mc.fencetargetsoldiers_mv.gotoAndStop(3)
};

if (_global.tGlobal == "target2" && _global.aGlobal == "ammo2" && _global.fGlobal == "fuse" && _global.hGlobal == "true"){
_root.mv_targetgrid.target2_mc.cannon_targets_mv.gotoAndStop(2)
} else {
_root.mv_targetgrid.target2_mc.cannon_targets_mv.gotoAndStop(3)
};

if (_global.tGlobal == "target3" && _global.aGlobal == "ammo3" && _global.fGlobal == "fuse" && _global.hGlobal == "true"){
_root.mv_targetgrid.target3_mc.tent_targets_mv.gotoAndStop(2)
} else {
_root.mv_targetgrid.target3_mc.tent_targets_mv.gotoAndStop(3)
};
_root.mv_gamecannon.gotoAndPlay(2);
};
any idea how I get around this problem?

Use Variable In A Movieclip Name ?
Hello, I've compromised my code so much and now i can't even get this working. Please help me. If someone could please point out what the correct code is for this.

It is to make movie simpler to design, once i click a button i put a number into variable (press button 2 it puts 2 into variable).

Set it global but is all on main timeline anyway. So, clipNo is what i put the number into. How would i then get into the command to show/move/play a movie clip?? Below is what i;ve been playing about with. The trace commands tell me the variables all work fine. I tried a second variable clipname but no joy either.

trace("number"+clipNo);
_global.clipname = "mc_"+clipNo
trace("name = "+clipname);

_global.clipname._visible = true;
mc_(clipNo)._visible = true;
or clipname._visible or mc_(clipname)

what works is mc_1._visible = true;

I'm really pushed for time now and if i can get this working then i can finish the game...help please!

Variable For Use In Movieclip
With an unique code I want to generate a digital person, with a head, middle and a lowerbody. I have a movieclip voor the head (instancename: a1) and also for the middle and the lowerbody (b1 & c1).

See the code I made:


ActionScript Code:
// variabelen
var uniqueId:String;

// fake id //
uniqueId = "a1 b1 c1";
//uniqueId = undefined

var my_str:String = uniqueId;
var my_array:Array = my_str.split(" ");
// forloop read array's
for (var i = 0; i<1; i++) {
        trace(my_array[0]);
        trace(my_array[1]);
        trace(my_array[2]);
       
        headVar = my_array[0];
        middleVar = my_array[1];
        lowerBodyVar = my_array[2];
               
        // Position elements
        headVar._x = 120;
        headVar._y = 100.5;
        middleVar._x = 120;
        middleVar._y = 163.5;
        lowerBodyVar._x = 120;
        lowerBodyVar._y = 221;
}

I thought this code would work, but it didn't...
If I trace the vars:
headVar = a1
middleVar = b1
lowerBodyVar = c1
This looks okay!

But it doesn't seems to work

How can I fix this, that the correct movieclips (a1 & b1 & c1) will load in Flash?? If I type "a1" on the place of headVar (to test), It does work great.

Please who can help me??

Variable In A Movieclip Name
hello, being a beginner I still dont get the syntax rules of AS ... could anyone help, please?

1. I have a variable called "num" which has a different value (1 to 6) everytime the timeline of the scene repeats

num = Number(random(6)+1);

2.here I would like to use "num" value in a movieclip name ("container" number should be changing according to the "num" value)

somevariable = container1_mc.cont1_txt;

how can i use the "num" value inside the movieclip names (replacing 1 in the example above)?

[fmx] Getting A Variable From A MovieClip Name
can anyone please tell me, what's the best way to get a variable when a button or movie clip is clicked that corresponds to a part of the name of the clip?

let me explain...

say i have four movie clips, clip01, clip02, clip03 and clip04.


Code:
for(i=1; i<5; i++) {
_root["clip"+i].onRelease = function() {
// set variable 'clipClicked' to 1, 2, 3 or 4
}
}
thanks in advance...

||| O ^ | + O ¬

[fmx] Getting A Variable From A MovieClip Name
can anyone please tell me, what's the best way to get a variable when a button or movie clip is clicked that corresponds to a part of the name of the clip?

let me explain...

say i have four movie clips, clip01, clip02, clip03 and clip04.


Code:
for(i=1; i<5; i++) {
_root["clip"+i].onRelease = function() {
// set variable 'clipClicked' to 1, 2, 3 or 4
}
}
thanks in advance...

||| O ^ | + O ¬

MovieClip To Variable How Does It Work?
I tried:
o1 = MovieClip"o1";


But it came up with the error:
Scene=Scene 1, Layer=other, Frame=1: Line 1: ';' expected
o1 = MovieClip"o1";


What did i do wrong?
Is it possible to turn movieclips into variables?

how do I do this?!

Movieclip.gotoAndStop(variable)
Hi,

i've got a problem with the movieclip.gotoAndStop(variable)command.
I have a movieclip(movie1) in which other movieclips(say 2,3 and 4) are on the timeline.

Inside the movieclips(2,3,4) I use the command _parent.gotoAndStop(variable. the variable is of course 2,3 or 4.
The problem is that the command only works at the last frame of the movieclip 2,3 or 4.

Does anyone know why this is and why I can't use this command in any other frame in the movieclip?

It seems flash just ignores the command unless it's at the last frame of the movie's timeline...

I know it's a vague problem but it drives me crazy !!

Leadman

Setting Variable In MovieClip
Hey all,

I think I know the answer to this but just wanted to check.
I'm trying to set the value of a variable in a movie clip from the root timeline.

If I create a Graphic this works fine as its using the same timeline.

I know that to set a variable for a movie clip you need to specify the instance path, but is this possible in flash4 ?

Thanks a million anyway!
:O)

Global Variable In Movieclip
Hi.
I've been working on this for ages, and have run into a problem I just can't figure out. It seems like a bug in Flash to me, what do you think?
I've stripped the project down to the basics to describe this problem. Here goes......

I have a simple movie with a single layer in the main timeline and a single frame on that layer.
I have 1 button and 2 instances of the same movie clip on the frame.
One instance of the movie clip is called 'Target_11', the other is called 'Target_12'.

Here is the actionscript I have on the frame in the main timeline:
Stop
Set Variable: "Block" = 0

Here is the actionscript I have on the button in the main timeline:
On (Press)
Loop While (Block < 2)
Set Variable: "Block" = Block + 1
Trace (Block)
Begin Tell Target ("/Target_1"&/:Block)
Go to and Stop (2)
End Tell Target
End Loop
End On


Each movie clip instance has a single layer with 2 frames.

Here is the actionscript on frame 1:
Stop

Here is the actionscript on frame 2:
Trace (/:Block)

When I run the movie I would expect the output window to show this:
1
1
2
2

But what I actually get is this:
1
2
2
2

Can anybody tell me how I can get the Trace statement in the movie clip instance to show variable 'Block' as '1' then '2' as it should do.

Thanks in advance for any help you can give. I've been working on this for ages and can't figure out what is happening.

If you would like me to email you this test movie, let me know.

Regards.
Damian.

Problem With Set Variable In Movieclip
Hello.

I have done a form where my visitor can type in information and then send to my e-post. All works good.

Now I have done a movieclip that uses several frames. The visitor cna move between the frames in the moviecklip with buttons.

Everyframe have i given propities, Set Variable, variable=object1-8 and value 8 differnet colours.

then I Creadted the variables object1-8 as textfields but it doesnt work. I want the variable to change when the moviclip change frame.

please help me!!
// erik

Add A Variable To A Movieclip Object?
If I load a moviclip/button to a movie, can I add a variable to the movieclip/button object?
I'm populating a movie with a bunch of clips that are just duplicates of a movieclip which act as a hyperlink. I can store the text of the hyperlink in the object.label variable, but I have a record id that has to be stored in some other variable for THAT specific movieclip/button. How can I do that?

MovieClip Variable Problem
Hi, This is my second posting here...I am not coming from the Sound forum....I should give up on this, but I'm convinced that there is a solution. The thread is below. Please post if you have a suggestion based on the information below. Thank you!

************************************************** ********************
Dear Flash Experts,

I would like to be able to access the value of a global variable that resides in a movie clip action handler-- on an action script frame on the main time line.

For example, if you look at the code that I'm using below...I need to be able to know what state the variable 'soundplaying' is in on the movie clip's associated frame action script in the main timeline. I need this so that I can tell the play head to go to another Frame label when the movie clip is finished playing. I've been fighting with this for a while and have recognized that the onClipEvent(enterFrame) is executed AFTER the frame script...so it never goes back to the framescript. I'm not sure. I can read the value of 'soundplaying' in the main timeline frame from the onClipEvent(load) handler, but I cannot get the value of 'soundplaying' to make it from the onClipEvent(enterFrame) handler to the maintimeline frame.

I hope this makes sense.

I'm using the following code
(which, with the exception of the global variable declaration, I thankfully copied from hp3's Sound Forum Fact number 25
http://www.flashkit.com/board/showt...threadid=299918 )

onClipEvent (load) {
mysoundobj = new Sound(this);
mysoundobj.attachSound("_root.musreflx");
mysoundobj.sndlength = 63100;
// 1000 milliseconds
mysoundobj.start();
startTime = getTimer();
_global.songplaying = true;
_global.Sit = "fuk";
}
onClipEvent (enterFrame) {
if (_global.songplaying) {
now = getTimer()-startTime;
if (now>=mysoundobj.sndlength) {
_global.songplaying = false;
// stop loop
trace(songplaying);
}
}
}


My frame code reads as follows:

trace(songplaying);
trace(Sit);
if (songplaying) {
stop();
} else {
trace(songplaying);
gotoAndPlay("symetrical");
}

Thank you for your help!

************************************************** *************

Report this post to a moderator | IP: Logged

02-08-2003 09:15 PM



hp3
Music & Sound Forum Moderator

Registered: Apr 2001
Location: Akron OH, USA
Posts: 1579
Not sure if this is directly related to your problem but it seems you are taking a Flash 5 coding approach and also using the _global directive wich is a Flash MX ActionScript feature.

if you want this to be backwards compatible with Flash 5, then I would not use the _global directive. Just make a variable that is scoped to the movie clip and use its target path to reference it from other timelines.

ex.
// declared inside mc clip event
songplaying = true;

// read from mc frame
trace(songplaying);

// read from main timleine
trace(targetpathtomc.songplaying)


************************************************** *************


Report this post to a moderator | IP: Logged

02-09-2003 05:16 PM


************************************************** *************
mellow


Registered: Mar 2000
Location: Chicago
Posts: 43
Still trying...
Dear hp3,

Thank you!
I do want it to be backwards compatible.
This is a tough one for me, I am still having a problem. I am still able to trace 'songplaying' at the Main Timeline action, ONLY during the onClipEvent(load) handler..Once it enters the onClipEvent(enterFrame) state, the Main Time line does not respond to the state change...but I know that it is working because I can trace a FALSE from the Movie Clip. I have not successfully gotten a FALSE state from the Main Timeline. Though, I have successfully gotten a TRUE state when tracing from the Main Timeline.

Please help if you can. I really appreciate it.

Details below:

Based on your advise, I've changed my code to the following:

MovieClip Action--
---------------------------------------
onClipEvent (load) {
mysoundobj = new Sound(this);
mysoundobj.attachSound("_root.musreflx");
mysoundobj.sndlength = 3100;
// 1000 milliseconds
mysoundobj.start();
startTime = getTimer();
songplaying = true;
}
onClipEvent (enterFrame) {
if (songplaying) {
now = getTimer()-startTime;
if (now>=mysoundobj.sndlength) {
songplaying = false;
trace(songplaying);
// stop loop
}
}
}
-----------------------------------------------------
Frame Action:

trace(_root.musreflx.songplaying);
if (_root.musreflx.songplaying) {
stop();
} else {
gotoAndPlay("symetrical");
trace(_root.musreflx.songplaying);
}
-------------------------------------------------------
Movie Clip Frame Action:

trace(songplaying);



************************************************** *************

Report this post to a moderator | IP: Logged

02-10-2003 05:53 AM



hp3
Music & Sound Forum Moderator

Registered: Apr 2001
Location: Akron OH, USA
Posts: 1579
in what frame of the main timleine do you attach the sound movie clip and in what frame of the main timeline are you checking the value of songplaying?

did you add enough frames to the mc so that it is still on the timeline at the point you check the value of songplaying?


************************************************** *************


Report this post to a moderator | IP: Logged

02-10-2003 03:02 PM



mellow
Member

Registered: Mar 2000
Location: Chicago
Posts: 43
>in what frame of the main timleine do you attach the sound movie clip and in what frame of the main timeline are you checking the value of songplaying?

I attach the sound MC in frame 40 of the timeline
I am checking the value of songplaying in frame 43...hmmm...


>did you add enough frames to the mc so that it is still on the timeline at the point you check the value of songplaying?


The mc frame run is about 430 frames...the actual time length is about 62 seconds. I stretched out the sound layer to cover the length of the the sound in the MC. Do I need to do the same on the Main timeline?


************************************************** *************

Report this post to a moderator | IP: Logged

02-10-2003 04:50 PM



hp3
Music & Sound Forum Moderator

Registered: Apr 2001
Location: Akron OH, USA
Posts: 1579
is the sound mc on the main timeline at frame 43 or is it only in frame 40?


************************************************** *************

Report this post to a moderator | IP: Logged

02-10-2003 05:45 PM



mellow
Member

Registered: Mar 2000
Location: Chicago
Posts: 43
The sound MC is on frames 40 to 43....thank you for keeping this up.

************************************************** *************
Report this post to a moderator | IP: Logged

02-10-2003 05:55 PM



hp3
Music & Sound Forum Moderator

Registered: Apr 2001
Location: Akron OH, USA
Posts: 1579
if the mc is still on the timline at frame 43 and you are unable to retrieve a value for songplaying then I have no other ideas to help you. soundplaying should return true in frame 43 because the sound is still playing at that time (it is roughly 430 frames long).

you should be able to read a variable within a movie clip at any time as long as the mc is visible on the main timeline at the time you poll the variable.

you might ask in the ActionScript forum as to why you are not able to read the soundplaying variable in frame 43.


________________

Passing A Variable To A Movieclip
Im trying to read a variable x in the root into a mc,

In the maintimeline at frame 1 I have x=100;


The I have a mc with
-------------------------------------------------------
onClipEvent (enterFrame) {
_rootx +=1
trace(_rootx); // 4
}
--------------------------------------------------------

The trace just returns 1

Why doesnt this work

Path To Movieclip As A Variable
why does this not work for movieclip 'x'?

path = "_root.x";
path._visible = 0;

(or any other property of 'x')

||| O ^ | + O ¬

Addressing Movieclip With Variable
Ok I have actually searched the forums and tried everything they said to get this to work and it doesn't work.

on (release) {
var laspos2 = _global.laspos;
trace(laspos2);
trace(_root.timeline.laspos2.timeline_hilite._curr entframe);
_root.timeline.newscroll = -40;
trace(_global.laspos);
this.timeline_hilite.gotoAndPlay(2);
}


I am trying to get this working:

I want to use a variable (laspos2) to dynamically address a movieclip.

var laspos2 = _global.laspos;
trace(laspos2);
trace(_root.timeline.laspos2.timeline_hilite._curr entframe);

It always gives me undefined for the path. (the laspos2 trace gives me the proper string value.) The mc's I am trying to address are named d1, d2, d3, etc.

If I do this:
trace(_root.timeline.d1.timeline_hilite._currentfr ame);

It gives me the proper currentframe so I know my path to that movieclip is working.

This is extremely frustrating and any help is greatly appreciated. I am on a tight time deadline so please don't hold back if you have any ideas. Thanks in advance.

How Can I Get A Movieclip To Run In A String Variable
I am trying to use the gotoAndStop(x) method of a movie clip to a movie that I keep a reference to in a string variable. How can I get the stringvariable content and use gotoAndStop() to make sure that the movie plays like I hardcoded the reference? I am confused here.

I tried doing like this but no luck

strMovie="myTestMovie";
gotoAndStop(strMovie,15);

Any suggestions? Thanks

Help Incrementing A Variable From A MovieClip
Hi all I need a little advice, I have a variable declared on the main time line, in my movieClip I need to increase that variable on the main time line. How do I increase the value of the variable in the main time line from the MovieClip Please help!!.

MovieClip Variable Not Available In Function? (MX)
How come this:
code:
for (count=1; count<=111; count++) {
temp = eval("shards.shard"+count);
temp.fallSpeed = randRange(-5, 10);
temp.slideSpeed = randRange(-5, 5);
temp.fallIn = randRange(0, 20);
temp.doesSpin = (randRangeRounded(1, 2));
temp.spinX = randRange(-3, 3);
temp.spinY = randRange(-3, 3);
temp._alpha = 50;
}
for (count=1; count<=111; count++) {
trace (temp.fallSpeed);
}


gives the intented results, however the following comes back undefined?

code:
for (count=1; count<=111; count++) {
temp = eval("shards.shard"+count);
temp.fallSpeed = randRange(-5, 10);
temp.slideSpeed = randRange(-5, 5);
temp.fallIn = randRange(0, 20);
temp.doesSpin = (randRangeRounded(1, 2));
temp.spinX = randRange(-3, 3);
temp.spinY = randRange(-3, 3);
temp._alpha = 50;
}
function crash() {
for (count=1; count<=111; count++) {
trace (temp.fallSpeed);
}
}
crash();


It seems as soon as I put it in a function, the variables loose their value?

Call Variable Into Movieclip
Hi all,
If i have a variable created in a frame how do i call that variable into my button movieclip? The movie clip is on the same frame where the variable was created.

Using A Variable To Target A Movieclip
Hey,

I have 10 buttons, that control 10 movie clips.

The 10 movieclips scale up and stop(); then it scale down on close which happens either on click or hopefully on the opening of another movie.
and its the close on opening of another movie I am having trouble with.

I would like to do it through actionscipt instead of using frames and frame labels, as eventually i will have more than 10.

I've set up a movie clip variable to define which movie clip is open. (which works and traces)

but now I'm stuck with how to take that variable information and have it close the movie. Or have the button target the variable which will say something like

on (press) {
movieclip1.gotoAndPlay(open);
variablename.goToAndPlay(close);
}

I dont even know if I can use the variable to target a movieclip.

I really hope this makes sense to someone out there!!

cheers

Rhiannon


----------------------------------------------------------------------

Ok so I worked it out with an if statement

but I was hoping there was a way I could do it without having a if statement for ever scenario:

Right now I have


on (press) {

if ( movieclip=="m2open" ){
m2.gotoAndPlay(close);
this.m1.gotoAndPlay(open);
this.m1.swapDepths(19);
} else if ( movieclip=="false"){
this.m1.gotoAndPlay(open);
this.m1.swapDepths(19);
}

if ( movieclip=="m3open" ){
m3.gotoAndPlay(close);
this.m1.gotoAndPlay(open);
this.m1.swapDepths(19);
} else if ( movieclip=="false"){
this.m1.gotoAndPlay(open);
this.m1.swapDepths(19);
}

}

Goes on to if (movieclip=="m10open")

Is there a simpler way to do this?

thanks

Rhiannon

Creating A MovieClip With Variable
Hi All,

Using flash 8 I'm trying to create a image loader that goes through a specific folder and loads each file named (image1.jpg, image2.jpg etc) sequentialy. It all works fine apart from the line (imageHolder + i._y = dis with 'i' being an increment that goes up by one and 'dis' being the height of the last image.


Code:
fileExists=new LoadVars();
fileExists._parent=this;
fileExists.onLoad=function(success)
{
if(success){
var nm=this._parent.createEmptyMovieClip('imageHolder'+i,i);
imageHolder + i._y = dis;
nm.loadMovie('Images/Image'+i+'.jpg');
}
else
stop();
}

fileExists.load('Images/Image'+i+'.jpg')
Can anyone help me with this, I basically need to know how to include a variable in the path.

- Thanks

[F8] Using A Variable To Target A MovieClip?
it seems this has been causing me quite a bit of trouble, as i don't understand it at all.....
i'm simply trying to pass a variable (holding a target) to a function to control that targeted movie clip.
sounds easy but i can not get it to work...
here's my function,, and i call it from the same timeline as
buttonRollout(vip)

function buttonRollout(whichButton) {
var i = 0;
trace(whichButton);
var newString = whichButton

while (i < 100) {

//do something here
whichButton._alpha = i;
i++;
}

now when i trace whichButton i get "_level0.vip" ????
why is this not just "vip" ??

so if i directly target vip._alpha = i in the while statement it targets correctly,,,so why can't i do this dynamically and use the variable the fill in my target???? it's really frustrating..

thanks
shane

Renaming Movieclip With Variable
I have a bunch of movieclips named "mc_Img_0", "mc_Img_1", etc. What I cant figure out is how to target a certain movieclip using a variable within a function. Here's an example:

for (i=0; i<5; i++) {
var renamedBtn:MovieClip = this["btn_Img_"+i];
renamedBtn.onRelease = function() {
mc_Whatever.gotoAndStop(3);
};

Unfortunately, I'm not using a for loop. I'm guessing it would look something like this:

function changeThis(randomNumber:Number) {
var renamedBtn:MovieClip = this("btn_Img_"+randomNumber);
renamedBtn.onRelease = function() {
this.gotoAndPlay(3);
};

But of course it doesnt work. Any help is appreciated.

Cannot Assign A Variable In A Movieclip
hi,
I'm sorry if this is a stupid question, but I don't understand what I am doing wrong here.
On my stage I have a movieclip 'my_movieclip'.

In this movieclip I load 'myfile.swf', and that works ok.

The 'myfile.swf' has a variable 'myvar' that I want to assign a variable to, but somehow that doesn't work with the code below.


PHP Code:



loadMovie("myfile.swf", "my_movieclip");
my_movieclip._x=50;//this works
my_movieclip._y=50;//this works
my_movieclip.myvar="hello";//this doesn't work




What must I do to be able to assign this variable?

thanks
Patrick

ps I am using flash8

Set Variable Inside A Movieclip
Hi All,

I try to set some variable inside a movieclip, so I use

_root.mc_name.var_name = 123 ;

so in movieclip "mc_name", there is a variable which equals 123



now I have duplicated this movieclip 12 times by "duplicateMovieClip", and named them mc_name1, mc_name2 .. mc_name12 , and then try to send variable into each movieclip,

so I try

for ... {

_root."mc_name" + id_number.var_name = 123;

}

what I try to do is that id_number will loop from 1 to 12, so a variable will be sent into mc_name1, mc_name2 .. mc_name12

but it does not work

SO, how should I make it work?

many thanks

Help With Creating A Movieclip Variable
hello. i am fairly new to flash. i am working on my flash site and need help with something.

i have 3 scenes. My preloader scene, splash scene and my main scene.
The main scene is reserved for my other pages as embedded swf's.

On the splash scene, i have my menu over an image.
the menu contains "about, services, portfolio and contact".

My question is, how do i set up a variable so that if the user presses the portfolio button, the portfolio swf will load on the main scene? or if the user presses the services button, the services swf will load on the main scene?

i hope my question is clear. Please help. I can upload my .fla file if necessary.

Defining Variable In Movieclip
I'm kinda new to AS3 right now, and I have a question.

How do you define a variable in a movie clip and access it in an event?

Thank you,
GamerFlash

[F8]Accessing MovieClip Using Variable Name
Say I have a variable

var tempName = "0";

I give a clip on stage the instance name 0. However i want to access the clip using tempName.

Its path would be
_root.0

But using the variable would be....?
_root.tempName doesn't work and
_root[tempName] accesses everything.

Any help on why these two methods don't work, and the correct method for using this way of access?

Any help appreciated,

Halcyon.

Placing Movieclip From Variable
I have a movieclip (transsquaresector) that I want positioned on the stage based on 2 variables from the previous frame (transsquarex & transquarey).

I have the following code:

transsquaresector._x = transsquarex;
transsquaresector._y = transsquarey;

I thought this would work but it is not. Any ideas? Should this work?

PS - it's Actionscript 2.0.

Ta.

[F8] Variable Controlling A Movieclip
Hi everybody!

Iv'e got a movieclip(character) that I want to push to the next frame once a variable(first) equals 1.

The problem is that the movieclip goes right through to the end.

How do I get the movieclip to stop at the next frame. I can't use frame labesls or refer to specific frame numbers because I want the movieclip could be on one of eight diffrent frames depending on the users success.

Here is the code!

Many many thanks in advance!!!!

Sumon


Code:
onClipEvent (load) {
_parent.character.gotoAndStop(1);
}
onClipEvent (enterFrame) {
}
onClipEvent (enterFrame) {
first = 0;
if (_parent.controller.speed>20) {
first = 1;
}
if (first == 1) {
_parent.character.nextFrame();
}
}

Get A Variable Inside A Movieclip?
Please refer to the newer post. I double posted on accident

Get A Variable Inside A Movieclip?
I'm sorry if this seems amateur but i'm still getting used to AS3.

I have my main timeline where i declare a String variable such as

Code:
var whichpack:String = "tenpack";
Inside a movie clip thats on the stage, I want to call this variable such as

Code:
trace (whichpack);
I'm getting
1120: Access of undefined property whichpack

How do I make the variable public or global so I can refer to it anywhere in the flash file?

I tried using a package with a class like this

Code:
package com
{
public class SampleCode
{
public var whichpack:String = "tenpack";
}
}
I put SampleCode.as inside a folder called "com" and then put

Code:
import com.SampleCode;
but it didn't seem to work.

Variable Movieclip Variables
Hello,

I am trying to make a variable movieclip variable.
Meaning that I want to make a movieclip in a function that is different everytime. I first tried it like this:


Code:
var 'loadMovie' + i + '_mc':MovieClip = new MovieClip();
Where 'i' is getting raised by one everytime the function gets runned.
This generates the error: 1084: Syntax error: expecting identifier before loadMovie.

So i want to call the movieclips loadMovie1_mc, loadMovie2_mc, loadMovie3_mc etc.

Hope some1 can help me with this..

Greets

Targeting A Movieclip Using A Variable
Hi there, I hope I can explain this clearly, I've made a flash video presentation which is divided up into 15 different movie clips which are like scenes or chapters. I've also built some buttons into my presentation which should allow the user to pause, jump one chapter forward or backwards and mute the background music. muting the music is fine but I'm having problems with the other 3 because I cant figure out how to target the 'chapter' movie clip from my pause button, each chapter movie clip has a unique name since the clips overlap on the stage during transitions, otherwise I wouldn't have any problems.

So what I've tried to do is set up a variable on the main timeline which changes every time a new chapter begins, so on my action layer on the frame where the new chapter begins I would have something like:

currentChapter = Chapter2;

So my pause button currently looks like this:

Code:
on(release){
_parent._parent.stop();
_parent._parent.currentChapter.stop();
_parent._parent.currentChapter.voice.stop();
_parent._parent.redwings.stop();
this.gotoAndStop(2);
}
if I trace _parent._parent.currentChapter it will return the desired value ex: Chapter2, also if I replace 'currentChapter' with 'Chapter2' and press the button while the movie is on Chapter2, it works perfect.

but I suppose the problem with my variable code is that it is looking for Chapter2 on the same timeline as my pause button and not two levels higher where it's located. I've been playing around with it for an hour trying everything I can think of, just not sure the proper way to make it read the variable and target it propery...I thought maybe if I changed my variable declaration to currentChapter = "_parent._parent.Chapter2"; but no dice, I'm out of ideas if anyone could help I'd really appreciate it.

lp

GotoAndPlay(1) Of My Movieclip Name Taken From Variable?
Hello, i'm looking to play the movieclip called "neck". but i am trying to write one function so i can change the evt.target.which to the name of the movieclip i would like to play.

this below code does not work, but it's how i thought it should be...



Code:
function rollOut2(evt:MouseEvent):void {
var where = evt.target.which
where.gotoAndPlay(1)
}

function rollOver2(evt:MouseEvent):void {
var where = evt.target.which
where.gotoAndPlay(2);

}

neckmc.addEventListener(MouseEvent.ROLL_OVER, rollOver2);
neckmc.addEventListener(MouseEvent.ROLL_OUT, rollOut2);
neckmc.which = "neck"

Use Variable To Create MovieClip
I have an issue where I have a MovieClip in my library that I'm exporting for actionscript, and I'd like to create a new instance of that MovieClip using a variable and am not sure how.

The MovieClip is in the library, exported with the Class "Box".

Normally, I'd just do: var thisBox = new Box();

But in this case I'm pulling the name "Box" from an XML list:


Code:
for each(var item:XML in boxXML) {
var tempBox:Sprite;
trace(item); // This outputs "Box" in this case
tempBox = new item(); // Here's where my problem is
addChild(tempBox);
}
I'm not sure how I can convert that variable in order to create the MovieClip using its value ("Box") for the name of the MovieClip.

MovieClip Defined By Variable
I'm trying to place a movieClip based on a variable.

In as2 you could do this:
this.targetMC.fishHolder.attachMovie(fishMovieClip Name, "mcFish1", this.targetMC.fishHolder.getNextHighestDepth();

How do you do it with AS3? For example, how can I make Spraycan1 relative?
spraycan1=new Spraycan1();
toolLayer.addChild(spraycan1);

Thanks in advance!

Accessing A Variable From A Movieclip
I am trying to set up a variable in my main timeline that I can access from movieclips. However this doesn't seem to be working for some reason. Here's the code that instantiates the variable in the first frame of my main timeline:


Code:
var leftTextVar:int = 0;
here's the code within a movieclip that I'm trying to use to access it:


Code:
LeftText.text = String(leftTextVar);
When I run this, I get this error:

1120: Access of undefined property leftTextVar.

So can anyone tell me why this isn't working?

Re-initializing Movieclip Variable
hi guys...

I am a new AS3 user. Can anyone help me on how to re-initialize my movieclip variable? I have created an actionscript that randomly display an image and will animate it. After the first image has been displayed, under certain condition, the routine repeats and will randomly select another image. My problem now is when the routine repeats, the first image still there added with the new randomly selected image.
I have this initialization:
var sp1:MovieClip = new MovieClip();
var sp2:MovieClip = new MovieClip();

I have assigned values in it by this code:
sp1.addChild(img1);
stage.addChild(sp1);

I tried using "removeChild" but was not able to make it work.

Thanks in advance for any help you can extend...

Attach Variable To Movieclip
I am stuck...
I get an array of data from a xml-file. From that XML-file I will send data to movieclips - in each movie clip I have a textfiled - to that I can easily send the data - but I would also like to store daya in the variable "namn" that I would like to use later -

I tried this in a array:

ActionScript Code:
sokvagen.skriv = arrImgXML02[item].namn;

But I did not work. Ideas?

MovieClip Path In Variable
hello, i am storing movieclip paths into an array. I am having a problem assigning properties to the movieclips using the array.


Code:
//i am looping through the movieclips and assigning the paths in this array
thumb_order.push([this,this.my_full_url,this.my_thumb_url]);

//later in the code
for (z in thumb_order){
if (thumb_order[z][1] == url){
trace (" FOUND ONE!!!! "+thumb_order[z][0]);
selected_thumb = eval(thumb_order[z][0]);
trace(selected_thumb);// this traces: _level0.thumbs.blank_mc.thumb_6
with(selected_thumb){
_alpha = 100;
}
}
}
but the with(selected_thumb) statement does nothing. I have also tried


Code:
for (z in thumb_order){
if (thumb_order[z][1] == url){
trace (" FOUND ONE!!!! "+thumb_order[z][0]);
var selected_thumb:MovieClip = eval(thumb_order[z][0]);
trace(selected_thumb);
with(selected_thumb){
_alpha = 100;
}
}
}
but the Output says that selected_thumb Object does not exist


Any help would be nice, thanks!

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