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




Reference A Clip Through A String With It's Name



Does anyone know if it's possible to reference a clip through a string variable containing the clips name? Example:

ActionScript Code:
var clip_name:String = "myclip_mc";Something(clip_name).alpha = 0.5; // <-- is this somehow possible?



ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 12-08-2008, 03:49 PM


View Complete Forum Thread with Replies

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

Using A String Variable To Reference A Movie Clip
I have an appended variable that i want to use to reerence a movie clip instance, but it dosnt work....

var blah_num:Number = 1;
blah = "blah" + blah_num;

_root.blah.gotoAndPlay(5);

I hope this explains what im trying to do. I have 15 instances of the same movie clip that are named "blah1","blah2",...etc. the blah_num variable changes and is appended to blah, and then I want to use the string var blah as a movie clip instance. I ma trying to use it in this form: blah.gotoAndPlay(10); etc...

Thanks in advance

Use A String To Reference An MC
i'm back again!

is it possible to use the contents of a string to reference a movieclip?

basically, i have created an array of strings from a text file. each string's content is the name of a movieclip. can i convert the string so i can then access each MC?

help! if i crack this, i've finished the whole project.

cheers!

String As Reference To Variable
I've been trying for weeks to find a way to use the string "OSL" point to my variable _root.OSL which is an array.
I've searched google in all the ways I can think of whit no result exept one which was about macromedia director. In director you could write something like _root["OSL"] to access the variable _root.OSL

Is it possible to do something like that in flash?

Thanks

[F8] Object String Reference
hello,

I have a problem using Strings and referncing to them within a function.

I have a tick box that i have created on stage that on release makes the tick visible or not visible.

however i want to pass on that visible state to another box that has the same instance name as the 1st but with a "_1" on the end. To do this i made the instance name as a String and passed that into the function, and then referenced this using '_parent[boxName]._visible = ...' As soon as i changed the reference to a String it stops working. ANY help please. I am trying to learn to write AS using relative code and not absolute, also i want to insert this AS principle into a larger project that will have 20+ of these check boxes.

The TickForum.fla is the work in progress, the tick working3 is just to help explain what i am trying to achieve visually.


Code:
function tickBox(myName:String){
var PrintBoxName:String = myName + "_1.mcTick";

trace(myName);
trace(PrintBoxName);

if (_parent[myName].mcTick._visible == false){
_parent[myName].mcTick._visible = true;
_parent[PrintBoxName]._visible = true;

trace("visible = true");

}
else if (_parent[myName].mcTick._visible == true){
_parent[myName].mcTick._visible = false;
_parent[PrintBoxName]._visible = false;

trace("visible = false");
}

}




/************************************************************
Call functions
*************************************************************/

leu1.onRelease = leu2.onRelease = function () {
var target:String = this;
trace(target);
tickBox(target);

}

String To Array Reference?
hi,

is there a way to get a reference to an array by string? in AS2 you could do this:
ActionScript Code:
var myArray:Array = new Array();
var myString:String = 'myArray';

myArray[0] = 'blah';

trace( this[myString][0] ); // trace blah

maybe something like you can get child with getChildByName or class getDefinitionByName?

cheers

How I Can Reference To Object By Its String Name?
Hello,

I need to get reference to object by it's STRING name. How it can be done?

ActionScript Code:
someVariable = new Object():Object;


anotherCopy = getValue('someVariable');

so what function instead of getValue I must to use to get the value of someVariable?

Reference A Component With A String?
_root.component.items("lstForms"), I know this is not right but something like this?

Thanks.

String Reference To Movieclip?
Hey guys, I have a stage full of movieclips (90 of them), each of which has an instancename. I've placed them on the stage manually because each has an irregular shape that has to fit neatly with the other movieclips.

I also have an xml file holding info corresponding to each of the 90 movieclips. I'd like each of these movieclips to display it's specific set of information on mouseover. The problem I'm having is that I can't quite figure out how to write a reference to an existing movieclip in actionscript 3, I know I can manually push each of the 90 movieclip instancenames into an array but I'd rather find a slightly more automated way of referring to a movieclip.

Say I have a movieclip named mc85, I'd like to be able to do something like:

var temp_mc:MovieClip = 'mc' +85;

Obviously doing the above is going to throw an error about supplying a string where a movieclip is expected.

Is there a proper way of writing the above pseudocode in AS3 or am I better of just writing an array and pushing the 90 instancenames into it manually?

Accessing A MC Via A Variable String Reference
Code:
var possibleName:String = "mcIReallyWantThisClip";
possibleName.addChild(mcChildClip);


Just wondering if there's an easy way to add the child to the "mcIReallyWantThisClip" rather than a clip called "possibleName"...

(I've used getDefinitionByName, but that seems to wants me to create a new instance of mcIReallyWantThisClip.)

Reference XML Object From Value Saved As String
I'm trying to access an XMLList object from an href in a textField.

For instance, I have an object: plogXML.day[0].file[0].@url. I want to be able to reference that object when the user clicks on a hypertext link in a text field.

For instance, <a href="event: plogXML.day[0].file[0].@url">Text to click</a>.

Clicking on the link calls the event handler, but how do I access the corresponding XMLList object from a string value. I can do trace(this["plogXML"]) but not further down the food chain than that.

As always, any help, yada, yada,

Jennifer

String Literal To Object Reference
Hi,

I have the name of a clip in a string variable, "current". I want to move the clip using that name to currentx, currenty. The name is the full name of the object, eg current == "_level0.myClip". How do I move it? This doesn't work:

[current]._x = currentx;


Thanks.


spin

Help Obtaining An Object Reference From A String
Hello,

I'm new to actionscripting, but I've got a strong handle on OOP and javascript, so I hopefully won't need too much help.

Basically here's my problem:

I've got a bunch of thumbnails that perform actions when clicked on or hovered over. In one of the actions, I'd like to base the position of an element on my thumbnail's x/y coordinates. However, I can't seem to grab a reference to the thumbnail. I'd like to do something like:

obj = document.getElementById('objectName');

I see in Actionscript 3.0 you can call "getChildByName('objectName');" , but I haven't found anything analogous in AS1.0.

Does anyone have any recommendations?

It might also work if, in the button's "on(press)" and "on(release)" commands I could just pass (the reference to) the thumbnail object to the function I'm calling. I don't know how to do this either. I intuitively thought "this" should work when I'm writing code for that thumbnail's actions, but it appears "this" refers to the stage or something else.

Any suggestions? Thanks in advance. I'm sorry if this has been asked before...I tried to search for answers first but couldn't find any.

Reference, Not Value Of A String Eval Workaround?
Hi
I'm trying to get some xml into a variable so I can pass it into another object. The problem is I have to construct the xml path with a string comprised of the name of a variable. If AS 3.0 had eval this might work but.. basically how can I get the actual xml:







Attach Code

// within a function of my parent movieclip, I want to assign the xml property of a nested movieclip.

var s:String = "_contentXml.children()."+_sceneClass;
trace(s);
mcModule.xml = s;

// Outputs:
//_contentXml.children().About
// TypeError: Error #1034: Type Coercion failed: cannot convert "_contentXml.children().About" to XML.

























Edited: 05/09/2008 at 12:54:11 PM by jctw769

String Reference To Sound Channel
Hello coKirupas,

Things are well on the as3-learning front, yet I'm running into a new problem. I need to reference to a sound channel using a string. My code is something like this:


Code:

var chLoop:SoundChannel;
chLoop = sndLoop.play(0, 999);
...and this works, the channel is playing. But then, later on, I need a construction like this:


Code:
var trans:SoundTransform = new SoundTransform();
trans.volume = 0.5;

var sChannel:String = "ch" + sCurrentSound;

// sChannel is now "chLoop"

this[sChannel].soundTransform = trans;
...and that last line throws Error #1010: A term is undefined and has no properties.
Is there another way to reference a sound channel using a string...?

Thanks!

Variable String Data To Reference Movieclip
I've been trying to search for this but I'm not really sure how to word what I'm trying to do.

I have all these movieclips that start with a naming scheme like mc_1, mc_2, mc_3, etc. and I want to assign a listener to all the movieclips. I was thinking an array for each of the different end numbers ( only because sometimes it might not be a number, maybe mc_aa43g) and then a for loop to go through the array and assign the listeners. Perhaps there's a better way, or perhaps I'm not grasping the reference movieclip title through a string variable... the actionscript (this was just a concept of the logic and obviously doesn't work) I was thinking of was something like this...


mcArray = new Array('1','2','3','aa43g');

for(i=0;i<mcArray.length;i++){
mcName = 'mc_' + mcArray[i];
mcName.addListener('someListener');
}

Any advice is appreciated. Thanks

Reference MC Or String Passed To Function Returns "undefined", But Works
I'm having a problem passing a reference name of a movieclip or a string to a function. No matter how I type rectanglename, (String, or MC) the movieclip created is named undefined, but it shows up. Can someone tell me what I've done wrong?

Thanks!

var rectanglename:MovieClip;
var recWidth:Number = null;
var recHeight:Number = null;
var bordersize:Number = null;
var fillcolor:Number = null;
var fillalpha:Number = null;
var bordercolor:Number = null;
var borderalpha:Number = null;
//
function drawRectangle(rectanglename:MovieClip, recWidth:Number, recHeight:Number, bordersize:Number, fillcolor:Number, fillalpha:Number, bordercolor:Number, borderalpha:Number):Void {
this.createEmptyMovieClip(String(rectanglename), this.getNextHighestDepth());
this[rectanglename].beginFill(fillcolor, fillalpha);
this[rectanglename].lineStyle(bordersize, bordercolor, 100, true, "none", "square", "miter", 3);
this[rectanglename].moveTo(0, 0);
this[rectanglename].lineTo(recWidth, 0);
this[rectanglename].lineTo(recWidth, recHeight);
this[rectanglename].lineTo(0, recHeight);
this[rectanglename].lineTo(0, 0);
this[rectanglename].endFill();
}
//
drawRectangle(rectangle, 320, 240, 3, 0xDD8844, 50, 0xDD8844, 100);

Dynamic Reference To Clip
I am having a syntax problem with a bit of actionscript.


Shouldn't this statement:

_root.majorMask.masterMC.maskFaces.neg1.createEmpt yMovieClip(nm,i);



Equal this one?:

wclip = maskFaces;
cname = _root.majorMask.masterMC[wclip].neg1;

[cname].createEmptyMovieClip(nm,i);

Can't Reference Movie Clip
Help! I can't reference this movie clip. Any sugeestions?


-----------------------------------------------
_root.wishlistbox = _root.attachMovie("newwishlist", "wishlist", d+37, {_x:60,_y:100});

trace("wishlistbox = "+wishlistbox); //outputs: _level0.wishlist

ref1 = _root['wishlist'];
trace("ref1.box = "+ref1.box); //outputs:undefined

ref2 = eval("wishlist.box");
trace("ref2 = "+ref2); //undefined

trace("wishlistbox.box = "+wishlistbox.box); //outputs:undefined


/*
// This is the code in the 'newwishlist' Movie Clip
this.createEmptyMovieClip("box", this.getNextHighestDepth());

//draw filled box
this.box.beginFill(0xffffff, 100);
this.box.lineStyle(1, 0x000000, 20);
this.box.moveTo(0, 0);
this.box.lineTo(750, 0);
this.box.lineTo(750, 80);
this.box.lineTo(0, 80);
this.box.endFill();

timelabel = "wlitem";
createTextField(timelabel, this.getNextHighestDepth(),30,10,200,20);
this[timelabel].multiline = false;
this[timelabel].wordWrap = false;
this[timelabel].border = false
this[timelabel].text = "wishlist";
this[timelabel].selectable = false;
this.timelabelformat = new TextFormat();
this.timelabelformat.bold = true;
this.timelabelformat.align = "left";
this.timelabelformat.font = "Arial";
this.timelabelformat.size = 15;
this.timelabelformat.color = 0xcccccc;
this[timelabel].setTextFormat(timelabelformat);


this.box.onRelease = function(){
trace(this);
}
*/
-----------------------------------------------

Thanks, Pete.

Help With Movie Clip Reference
Hi Everyone,
Please help me with this script:

rootMovie.Fla code:
courseObj.onPress = function(){
txtIntro._visible = 0;
loadMovie("courseObj.swf", mcPlaceHolder);
}

As you can see I used a button to trigger a swf to load into a MC called "mcPlaceHolder". This works.


courseObj.Fla code:
function txtBasicFunc(mcName,mcAlpha){
_root[mcName]._x = _root._xmouse;
}


This works by itself, but when load into mcPlaceholder in rootMovie.Fla it doesn't work. I know that the _root[mcName] array must be the problem and this is where I need help.

thankyou

How To Reference To A Movie Clip
Hello

I have a movie clips with 2 buttons (a red and a blue). When I do a mouse over on the red button my blue button will come visible.

When I drag my movie clip to the stage I can see the red button and the blue button will be available when I do a mouse over on the red button

Now I want to apply an action script on the scene for my blue button that makes the time line go to frame 20. But I am not sure on how to reference the button from the movie clip. I get an error with a null reference.

I have attached my scenario. I am new to AS3 so this is maybe a simple question

Thanks
Tanja

Movie Clip Reference
If i have movieclipD iside movieclipC iside MovieclipB inside MovieclipA whose parent is the _root and i would like to reference MovieClipD in terms of the _root and not its parent. I know i could do it mathamatically calculating the X Y of every parent but i was wondering if there was a simpler way to do it?? for instace something like "movieClip._xworld".

Please and Thank you.

Please ask me to clarify if i have explained it poorly.

Reference To Namless Clip
Hi,

how can I reference a namless clip in as3? In the debugger I only can
see my named clips but I don't see where the other clips are. I try work
without names to easily copy them without creating a new name for every
new clip.

TIA

How Do You Reference The Fill Of A Clip?
Hi,

I've created an empty movie clip and filled it with beginFill, giving it and rgb and alpha property. How do I reference this fill to change the alpha or color? Referencing the clip by name isn't working,

cheers

K

_root[string Mc Reference].gotoAndPlay("label");
Why is this not working? I know my string is correct by trace.

clipA.clipB.gotoAndPlay("label");
_root[string mc reference].gotoAndPlay("label");
string mc reference is clipA.clipB exactly

Thanks.

Using A Variable To Reference A Movie Clip
This has got to be simple....
How do you use a variable to reference a movie clip which is linked from the library?
eg, I have a movie clip linked as movie1. And a variable called varmovieclip.
and I want to say - varmovieclip.play()???????

How To Reference Arrays In A Movie Clip
I have dynamic and input text fields in a movie clip
and trying to referance them in a for loop

for (i=0; i<2; i++) {
yoselfMC["varLineTot"+i] = yoselfMC["varLotQty"+i]*aryPrc[i];
Total += yoselfMC["varLineTot"+i];
}

where
yoselfMC is the movie clip instance name
varLineTot1, varLineTot2,.. are dynamic text variable names
and
varLotQty1, varLineQty2,.. are input text varible names

code must calculate total order price but does not

any suggestions about referancing varibles in a movie clip in this manner..
by the way.. should i do something to insert(or attach?) varibles to movie clips..

Reference Button In Attached Clip
I am trying to reference a button inside a movieclip. The movieclip is placed on the stage via attachmovieclip.

right now the movie attaches to the stage, but the button in the that movie doesnt work. How do I reference it?

code:
_root.createEmptyMovieClip("mc", 999);
btnbios.onRelease = function(){
mc.attachMovie("mymc", "mymc", 999);
}


mc.mymc.mybtn.onPress = function() {
trace("Button Pressed");
};

Movie Clip Reference Within A Class
Having problems dynamically creating a movieclip reference to pass to another class.

Basically I have a Game class and a Boiler class. The Game class contains a property called "mcReference" which is being created correctly as "_level0.game_mc" when I create the Game instance

var myGame = new Game(this);

Within the Game class I have a method to create 9 Boiler instances.

i.e


Code:

public function create_Boilers():Void {

arrBoilers = new Array();

for (var i:Number = 0; i < numBoilers; i++) {


var vBoilerRef:MovieClip = mcReference["boiler" + (i + 1) +
"_mc"];
var vBoiler_Obj:Boiler = new Boiler(vBoilerRef);


}

}
If I do a trace on vBoilerRef, I get undefined.

Any ideas what I am doing wrong?

The code for the 2 classes is as follows:


Code:

import Boiler;

class Game extends MovieClip{


// -----------
// Constructor
// -----------



public function Game(passed_mcReference:MovieClip) {


mcReference = passed_mcReference;
trace ("Game mcReference = " + mcReference);


}

public var mcReference:MovieClip;
public var arrBoilers:Array;
public var numBoilers:Number


public function init():Void {

numBoilers = 9;

}



public function create_Boilers():Void {


arrBoilers = new Array();

for (var i:Number = 0; i < numBoilers; i++) {


var vBoilerRef:MovieClip = mcReference["boiler" + (i
+ 1) + "_mc"];
var vBoiler_Obj:Boiler = new Boiler(vBoilerRef);


}

}

}
##############################


Code:


class Boiler extends MovieClip{


// -----------
// Constructor
// -----------



public function Boiler(passed_mcReference:MovieClip,
passed_ID:Number) {


mcReference = passed_mcReference;
trace ("Boiler mcReference = " + mcReference);
numID = passed_ID;
trace ("numID = " + numID);



}

public var mcReference:MovieClip;
public var numID:Number;
private var numInitialRotation:Number = -83.5;


public function reset_Needle():Void {

mcReference.guage_panel_mc.needle_mc._rotation = numInitialRotation;


}


public function set_Needle_Rotation(passedRotation:Number):Void {

mcReference.guage_panel_mc.needle_mc._rotation = numInitialRotation;


}

}

Reference _x Position Inside Clip
i am having problem referencing _x position of a movieclip inside another movieclip...its giving me a weird number and moving faster...here is an example.

I have b1 clip and c1 inside but if if put this.

b1.onEnterFrame = function(){
this._x = _xmouse;
trace (this._x);
}
b1.c1.onEnterFrame = function(){
this._x = b1._x ;
trace ("c: " + this._x);
}

the c1 moves faster then b1...what's up with that......thanks everyone.

Reference Child Clip From Parent
I'm using actionscript 2.

I have a main movie clip. In that movie clip I have 2 children movie clips. I want the 2 children clips to be able to control each other upon clicking buttons.

This code has been placed in the main movie clip:

home.map_btn.onPress = function ()
{
loadMovie("http://apsleycottage.com.au/flash/town_location.swf", movie_holder_mc);
};

The map_btn is located in a child swf called home. The home swf is dynamically called into the place holder called left_movie_holder_mc which is located within the main clip.

I want the main movie to register a click of that map_btn and replace a the movie currently in the movie_holder_mc with a new one called town_location.

What I have done does not work and I am not sure if I have referenced the the button properly from the main movie. I would appreciate any help.

The temporary page is located at:
http://apsleycottage.com.au/Apsley_Cottage3.html

Cheers

Crossy

Array Movie Clip Reference
Hi
I got some movie clips' references in an array as follows:

Code:
var buttons:Array = new Array(architektura_mc, urbanistyka_mc);
These movie clips are nested in a movie called 'menu_mc', so I can reference to them like so:

Code:
menu_mc.architektura_mc.property = value;
However, I'd like to facilitate my array in the following way:

Code:
menu_mc.buttons[0].property = value;
It won't work since when I trace menu_mc.buttons[0], it's apparently undefined. How come?

How To Reference Movie Clip In Button
Hello,

I have a button, lets say its linkage name is btn. From script in the main timeline I am adding the button (from the library) to a movie clip with attachMovie, giving it an instance name btn1. This has been working fine for me (however, please correct me if I should not be using attachMovie on buttons).

This button, in the Up frame, has a movie clip with an instance name interior. Is it possible, after I call attachMovie and create btn1, to reference this interior movie clip, like: _root.outer.btn1.interior ? I can successfully reference btn1 with _root.outer.btn1, but _root.outer.btn1.interior is undefined.

If I list objects while debugging, I can see a target: _root.outer.btn1.instance63. I realize that Flash has generated that instance name, but why hasn't it used the "interior" name I assigned inside the button?

Please excuse my lack of knowledge here, and know that I've spent a number of hours researching this before posting. Any help would be appreciated.

Thanks,
M

Ways To Reference A Movie Clip?
Can anyone explain why within a function this would work: colorSwatch_0._alpha-=10;

But this would not? this["_root.colorSwatch_"+0]._alpha-=10;


I am certain that the reference is solid, and I can access other variables in the same manner (dynamic text fields).

Any clues?


Thanks muchly


b

Movie Clip Reference Problem
Hi there, 1st of all, thank you for all those who have helped me out for that last week. I have gained so much information this week more than I do in a month. The progress of my project is going because of this forum.

2nd, I run into another question.

I have 1 index movie (_root). Inside this movie, I have a container_mc, and I load external swf file into this container.

For examble, I load a news.swf into the container_mc

But when I reference into a mc inside the _root timeline of news.swf, It doesnt recognize it.

For example: I have a myMovie_mc inside the _root timeline of news.swf
How do I make an absolute reference to this myMovie_mc?? ( I have a button inside myMovie_mc, and onRelease, I want it to play the 2nd frame on myMovie_mc

This doesnt work:
_root.container_mc.myMovie_mc.gotoAndPlay(2);

A quick solution is appreciated. Thanks guys.

FMX: Get Reference To Clicked On Movie Clip
New to flash!
I normally write javascript code, so I wonder how to do this.
In JS "Microsoft IS" you'll write code like this:

document.onclick = func;

function func()
{
var obj = event.srcElement; //And there I have reference to the object;
}

The graphic designer creates flash drawings and then converts whatever objects to movieclips. Then passes them over to me. All these "mc" need the same action applied to them. So I don't need to know how many they are or their names....Can this be done in Flash???
Thanx

Using Variable To Reference Movie Clip?
In AS2 I used to be able to reference a movie clip using a variable like this:


Code:
var target = nameofmovieclip;
I've been looking for an answer on how to do the same thing AS3 but with no luck. I'm trying to create a dynamic homing missle, but unfortunately everything I've tried just generates errors.

Does anyone know how to accomplish something like this is AS3?

Removing A Movie Clip Reference
Last edited by chance : 2003-01-27 at 06:31.
























For some reason, I can't seem to remove the reference to an unloaded movieclip that is contained in a movieclip that is contained in another movieclip that has been loaded using attachMovie(). I know the clip is being removed because listing the objects in the movie just shows the reference to the removed clip, not the objects within the removed
clip.



------------- Code ---------------
item = itemPath.attachMovie(itemClip, "item" + i, i);

var mp3 = item.mediaType_mc.mediaMp3_mc;
trace(mp3); // path to mp3
unloadMovie(mp3);
trace(delete mp3); // false

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

I've tried:

mp3.unloadMovie()
unloadMovie(mp3)
mp3.removeMovieClip()
removeMovieClip(mp3)

Is there something I'm missing here? I don't have any code anywhere that references these clips so I can't for the life of me figure out why I can't delete their reference.

Any help is appreciated, or if you know a way in the debugger or somewhere else to show all references to a given object, that may help too. I may have set a variable somewhere that references these clips and forgotten about it.

Thanks.

Mark Chance
mchance@ideo.com
IDEO
http://www.ideo.com

Movie Clip Reference Issue
I'm having this problem quite often now, I know it's kinda vague to tell, but it's basically this; reference to movieclips just stop working for no apprent reason.

For instance, I have this project where I have a movie clip at the stage and I use code from the same fla to make a reference to it and it just doesn't work.

Say myMC.buttonMode = true; to make it change the mouse arrow when the cursor is over the MC.

But if I make it simple, by deleting everything else but the part of the code where it makes the reference the MC and the MC itself, it works!

That's not the first time that it happened to me, so I wonder if it's a kind of well know bug that I should be aware of, or something...

Reference Current Movie Clip
how do you reference the current movie clip.

for example, as part of my "skip intro", i would like to stop the current playing movie clip.

this.stop() seemed reasonable but it does not work.

Loosing Reference To Movie Clip
I'm somehow loosing my reference to my movie clip i created dynamically.... can someone tell me what's wrong with this code.

var y=0;
var x=0;
var imageHolderWidth = 276;
var imageHolderHeight = 362;
var gap=50;
// loop through XML and place in array
for (var i=0;i<2;i++) {
var image = "last10_image_"+i.toString();

_root.createEmptyMovieClip(image,50+i);

var imageHolder = eval(image);
imageHolder._x=x;
imageHolder._y=y;
imageHolder.createEmptyMovieClip("_tn"+i,100+i);
mv_sub_image = imageHolder["_tn"+i]

trace(_root[image]["_tn0"]);
with(mv_sub_image){
_x=1.5;
_y=1.3;
_alpha=60;
with(imageHolder){
lineStyle(2,0xA0A0A0);
moveTo(0,0);
lineTo(imageHolderWidth,0);
lineTo(imageHolderWidth,imageHolderHeight);
lineTo(0,imageHolderHeight);
lineTo(0,0);
}
loadMovie("glamour.jpg");
}
_root[image].onRollOut=function(){
_root[image]["_tn0"]._alpha=60;
}
_root[image].onRollOver=function(){
_root[image]["_tn0"]._alpha=100;
}

currentNode = currentNode.nextSibling;
x = x + gap + imageHolderWidth;

//set the max image that can be displayed.
if(i>=1){break};
}




if you look at the trace output .. the first movie clip is undefined after the second loop.

How Do I Reference A Clip Inside A Scroll Pane?
how do i reference a moviclip that's placed inside a scroll pane...or is this even possible?
hmmmm...thanks

How To Reference A Movie Clip In Main Swf From A Class?
I'm a little ahead of myself in doing AS 3 for a client - before I have complete understanding myself.

Here's where I am stuck -

In the main swf(fla) I have "presentation_mc" which is a movie clip with many keyframes. Later designers will add/remove keyframes as needed. So I also have to generate numbered buttons dynamically.

Here is the code that generates the custom buttons in the main.swf:

function placeButtons():void{
var i:int
for(i=0; i<varNumOfSections; i++){
var varTemp:Number = i + 1;
varButtonLabel = String(varTemp);
varButtonX = varButtonFirstX + (35 * i);
varButtonOver = sectionArray[i];

var b1:Button_mc = new Button_mc(varButtonLabel, varButtonX, varButtonY, varButtonOver);

mySprite.addChild(b1);
}
}

----- end code in main.swf

Here is the custom class for Button_mc:

package{

import flash.display.MovieClip;
import flash.text.TextField;
import flash.events.MouseEvent;

public class Button_mc extends MovieClip{
public var varLabel:String;
public var varX:Number;
public var varY:Number;
public var varOver:String;

public function Button_mc(varLabel, varX, varY, varOver){
this.label_txt.mouseEnabled = false;
this.label_txt.text = varLabel;
this.x = varX;
this.y = varY;
this.toolTip_mc.over_txt.text = varOver;

this.toolTip_mc.tipBacker_mc.width = this.toolTip_mc.over_txt.textWidth + 20;
this.toolTip_mc.visible = false;
this.buttonOver_mc.visible = false;

this.buttonMode = true;

this.addEventListener(MouseEvent.CLICK, clickHandler);

}

private function clickHandler(event:MouseEvent):void {
var tempVar:String = this.label_txt.text;
//trace("You clicked " + tempVar);
buttonClick(tempVar);
}

function buttonClick(tempVar:String):void{
trace("I want to go to presentation_mc frame # " + tempVar);
//presentation_mc.gotoAndStop(tempVar);
}

}
}

---- end Button_mc.as

Note the red and bold traces fine on clicks - but I can't actually reference the movie clip "presentation_mc" from here.

I'm really sorry if this is simple - referencing is always the second thing I check on errors - after spelling. But I am getting a specific 1120: Access of undefined property presentation_mc error.

I am working my way through Moock's book on AS 3 at a feverish pace, but if I can't get this sussed I am in serious trouble for today.

I greatly appreciate anyone's help - whether simple or conceptual.

How Do I Reference The External Movie Clip's Button?
I'm loading a movie into a container (a navigation system). Now I want to put in some code in the first swf, not the external swf, to change the alpha of a movie clip. Can someone help?


Code:
var navLoader:Loader = new Loader();
gavholder.addChild(navLoader);
var navURL:URLRequest = new URLRequest("dock.swf");
navLoader.load(navURL);
navLoader.x=0;
navLoader.y=0;
navLoader.scaleX=1;
navLoader.scaleY=1;
I thought I could just say this


Code:
gavholder.c1.addEventListener(MouseEvent.CLICK, camp);
function camp(event:MouseEvent) {
gcrmcholder.alpha =50;
}
Regards,

Glen Charles Rowell

Using A Variable To Reference An Already Existing Movie Clip?
Hello,

I have been struggling with what I suppose is a very simple issue: I am importing content into my application via a text file, this all works fine. I have about 10 different movie clips on the parent timeline that I have hidden (dc_mc.visible = false.

So what I need to do is take one of the variable names that I've got from my text file and use its value to "turn on" one of these hidden movie clips.

So I'm trying stuff like:

var directory = e.target.data.directory; // Grabs the data, sets var
var raceNameButton:String = directory+"_mc"; // Set data into new var
raceNamesButton.visible = true; // display movie clip with var name

and it's giving me all sorts of problems. I know I can do this with ActionScript, but just can't seem to get it to work.

Any thoughts out there?

Is A Reference To A Clip Of Type MovieClip Or Object?
When declaring a variable using strict data types where the variable is a reference to a movieclip, is the variable type a MovieClip, Object, or something else?

e.g.:

var circleMc:[TYPE] = _root.circle_mc;

Can't Reference A Movie Clip Array Via For Loop
Hello everybody, I have this problem since many weeks ago, I can't figure out how to resolve it. My partial code is:

function checkCollision(rect) {
for(j=0; j < drop.length; j++) {
temp2 = eval(drop[j]);
if(eval(rect._droptarget) == temp2){
rect._x = temp2._x;
rect._y = temp2._y;
}
else {
rect._x = rect.origX;
rect._y = rect.origY;
}
}
}

I send to the function a movie clip that I use for drag and drop, so when I drop this function is called. The problem is that of the three rectangles that I use for contain the others, only the last senses the drop target. I read the Canadian post of frequently asked questions, and one of the questions is very similar, but I can't figure out how to apply it here. Any help please. Thanks

Pass Reference Of Movie Clip To Function?
Hey guys,

I'm trying to do something like this, but for some reason it isn't working...


ActionScript Code:
function mouseClickHandler(t:MovieClip):Void {       if(!t){        trace("no target");        var t:MovieClip = this;    }    else{        trace(t._name);    }}// using a call to this function I want to simulate a click on navItem_2mouseClickHandler(container.navItem_2);


Any idea why this shouldn't work?
Should I do it as a string or what?

Update:

Hmm, I replicated this situation in a blank movie and it works as it should. Really confused now.

Dynamic Movie Clip Reference Problems
Last edited by Codemonkey : 2006-08-18 at 10:30.
























i'm trying to convert the following statement:


ActionScript Code:
line_mc_1.moveTo(end_mc_1._x , 353);

I'd like to replace "mc_1" with the variable "currentSWF". by doing this:


ActionScript Code:
whichLine = "line_" + currentSWF;
whichEndX = "end_" + currentSWF + "._x";
 
eval(whichLine).lineTo(eval(whichEndX), 353);

...only the first eval is working. Is there a better way of doing this? I'm basically trying to dynamically generate the reference to the MC property. I've tried other approaches with no success.

Thanks in advance!

Raphael

Loosing Reference To My Movie Clip When Create Dynamically
I'm somehow loosing my reference to my movie clip i created dynamically.... can someone tell me what's wrong with this code.

var y=0;
var x=0;
var imageHolderWidth = 276;
var imageHolderHeight = 362;
var gap=50;
// loop through XML and place in array
for (var i=0;i<2;i++) {
var image = "last10_image_"+i.toString();

_root.createEmptyMovieClip(image,50+i);

var imageHolder = eval(image);
imageHolder._x=x;
imageHolder._y=y;
imageHolder.createEmptyMovieClip("_tn"+i,100+i);
mv_sub_image = imageHolder["_tn"+i]

trace(_root[image]["_tn0"]);
with(mv_sub_image){
_x=1.5;
_y=1.3;
_alpha=60;
with(imageHolder){
lineStyle(2,0xA0A0A0);
moveTo(0,0);
lineTo(imageHolderWidth,0);
lineTo(imageHolderWidth,imageHolderHeight);
lineTo(0,imageHolderHeight);
lineTo(0,0);
}
loadMovie("glamour.jpg");
}
_root[image].onRollOut=function(){
_root[image]["_tn0"]._alpha=60;
}
_root[image].onRollOver=function(){
_root[image]["_tn0"]._alpha=100;
}

currentNode = currentNode.nextSibling;
x = x + gap + imageHolderWidth;

//set the max image that can be displayed.
if(i>=1){break};
}




if you look at the trace output .. the first movie clip is undefined after the second loop.

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