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








Using A Variable String As An Instance Name


Hey Everyone,

I'm making a map and when you hover over a state it has a pop up with some information, pretty easy stuff. Well, I'm using this as my code(HoverCaption Tutorial)...



Code:

Missouri.onRollOver = function() {
captionFN(true, this._name + "
Carriers: " + ranString[numState] +
"
Total of " + ranCount[numState] + " Carriers.", this);
this.onRollOut = function() {
captionFN(false);
};
};
What I'd like to do is instead of having to make this for every state just pass in the instance name which is the name of the state. I thought my code would look something like this.

for button...

Code:

on (rollOver){
var numState:Number = 25;
var strState:String = this._name;
}
for other code...

Code:

strState.onRollOver = function() {
captionFN(true, this._name + "
Carriers: " + ranString[numState] +
"
Total of " + ranCount[numState] + " Carriers.", this);
this.onRollOut = function() {
captionFN(false);
};
};
Well, that doesn't work, I didn't know if there is a way to do that, maybe threw a method. Thanks for the help!




KirupaForum > Flash > Flash 8 (and earlier)
Posted on: 11-20-2006, 07:01 PM


View Complete Forum Thread with Replies

Sponsored Links:

String Variable -> Instance Name?
Hello There.

It is possible to use a String to identify a symbol instance?

Let's say I have several instances of a symbol movie clip. The instances are called mc_Symbol_AA, mc_Symbol_BB, mc_Symbol_CC... etc. Also I've defined a string varible called instance_name. Some script assigns this variable a different value every time, so the value will be "AA" or "BB" or "CC"... etc.

What code will be necesary to use this string to build the full name of the instance ("mc_Symbol_" + instance_name, an play it? On something like this:

Code:
on (relase) {
_root.Here will come some fuction to complete the instance name.play()
}
It may be a simple question, but I cannot find any documentation or example for this. Thank You!

View Replies !    View Related
Loops, Combine String With A Variable, Instance Name (mc)
Ello,
First of all, great forum ..

I'm quite new to actionscript, do have experience in java (js) and quite a lot with php, but actionscript? nope ..

I have to do this little project, and I wanted to use a loop for a hitTest for not running thru walls ..

I'm using a walls as a mc with an instance name and then test inside the object that's not suppose to run thru it to do a hitTest that equals the instance name of the wall mc like this;


Code:
(this.hitTest(_root.verticalLeft1))
Now I'm copying this code for all the other walls, verticalLeft2, verticalLeft3, ..4, also using horizontalTop1, horizontalTop2, ..3, etc etc ...

I was planning to use a loop so i don't have to copy it 20(x4) times, like this


Code:
for(var i:Number = 1; i<20; i++) {
var wallName = eval("verticalLeft" + i);
if (this.hitTest(_root.wallName)) { _x = _x+1; speed = 0; }
}
Now, the way I was thinking is that while looping, the wallName should be verticalLeft1, verticalLeft2, 3 etc .. identical to the mc with her instance name .. but it doesn't work .. obviously cause I don't know how else it should work .. Am I not suppose to use a String here? or at all, is it a String? cause var wallName:String = eval("verticalLeft" + i); doesn't work either .. or is eval(); totally wrong? .. pfff i've lost it

in PHP it would be something like ${"verticalLeft".i} .. but it's not php is it!

Well.. any help would be appreciated .. thanks ..

View Replies !    View Related
String Method From Instance Name
I'm having trouble with this(to make it quicker I'll just write here the necessary info):

I have a variable called currentURL.
this variable containes the instance name of a movieclip(in this case it's home).

I want to write a string with the instance name WITHOUT THE INITIAL _LEVEL0 PATH ELEMENT.
As I try to make a string from the variable with:

currentURLstring = new String(currentURL);

The string returnes:

_level0.home

I then try to slice it in many ways, let's say with substr:

currentURLstring.substr(7);

In theory the function showld produce a string like this:

home

...instead I still get the full path....

WHY?!?!?!?!?!?!
where am I mistaking?

here is the code:

// home is the instance name for a movieclip.
currentURL = home;
currentURLstring = new String(currentURL);
currentURLstring.substr(7);
StatusUpdate(currentURLstring);

View Replies !    View Related
Instance Name & String-problem
Hi again,

This is probably a silly syntax mistake, but I can't figure it out:

This works :


Code:
Bimg= function(targetMC){
trace("targetMC: " +targetMC)

//here is the problem:
var OrigStr:String = "_level0.mc1.thumb.holder"
trace("OrigStr:" +OrigStr)
// end problem
var charstart:Number = OrigStr.indexOf("mc")
var charend:Number = OrigStr.indexOf(".thumb")
var amount:Number = charend - charstart
var endResult:String = OrigStr.substring(charstart, charend)
trace("result: "+ endResult)
}
this returns:


Code:
targetMC: _level0.mc1.thumb.holder
OrigStr:_level0.mc1.thumb.holder
result: mc1
But this won't:


Code:
Bimg= function(targetMC){
trace("targetMC: " +targetMC)
// replaced the following line:
var OrigStr:String = targetMC
trace("OrigStr:" +OrigStr)
var charstart:Number = OrigStr.indexOf("mc")
var charend:Number = OrigStr.indexOf(".thumb")
var amount:Number = charend - charstart
var endResult:String = OrigStr.substring(charstart, charend)
trace("result: "+ endResult)
}
returns:


Code:
targetMC: _level0.mc1.thumb.holder
OrigStr:_level0.mc1.thumb.holder
result: undefined
First I thoughed I could solve it by replacing that line for :
var OrigStr:String = targetMC.toString
but that doesn't help either.

Anyone?

Thanks, again,

Papermouse

View Replies !    View Related
Setting String To Instance Name
i've got an array with 5 strings.

i want to pass these through a for loop and set them as an instance name. the instance name is one of a textInput component. it recognizes the name. but it won't read the .text attribute.


Code:
for (var i:Number = 0; i < mcArray.length; i++)
{
var tempName:MovieClip = mcArray[i];
trace(tempName);
if (tempName.text == "")
{
checkArray[i + 1] = false;
}
else
{
checkArray[i + 1] = true;
}
}

View Replies !    View Related
Convert String To Mc Instance
hello

code :
// this bit goes into a TextField prototype

function validate(obj:Object) {
wrongArray.push(obj + "error")
}

// this is my func

if (wrongArray.length<=0) {
sendMail();
} else {
for (i=0; i<wrongArray.length; i++) {
var themc:MovieClip = wrongArray[i];
//trace(typeof(themc) + " / " + i + " // " + wrongArray[i]);
showError(themc)
}
}
}
function showError(mc:MovieClip):Void {
trace(typeof(mc))
}

the output is always String how do i convert this to MovieClip instance

View Replies !    View Related
Get Movieclip By Instance Name String
This is a really simple newb question:

Given an instance name in a string variable like var x = "instancename", how can I get the actual movieclip with that instance name?

Thanks in advance!

View Replies !    View Related
How To Convert A String To A Instance Name?
Hello!

Im new to coding and ActionScript. I have a problem where I have a String that contains an instance name of a button (lets say the instance name is _level0.application.form1.A1 ), the problem is that I dont know what to do to get to use the buttons instance name ( what i have to do is to make some changes to _level0.application.form1.A1._x and _level0.application.form1.A1._y )

See the code below.

Thanks for the help


PHP Code:



//myNode.firstChild.nodeValue=<msg>_level0.application.form1.A1,100,100</msg>

var myString:String=myNode.firstChild.nodeValue;

//myString= "_level0.application.form1.A1,100,100"
var myArray:Array = myString.split(",");

//myArray[0] = _level0.application.form1.A1 -> toDrag = _level0.application.form1.A1

var toDrag_btn = myArray[0];

// NOW I NEED TO USE THE BUTTON _level0.application.form1.A1
// IT IS NOT DONE LIKE THIS BUT MAYBY YOU GET THE IDEA BELOW
toDrag_btn._x=100;
toDrag_btn._y=100; 

View Replies !    View Related
Generate Instance Name From String
This is probably a really simple question. I have a movie with say, 10 dynamic textfields called "description1", "description2"... etc

In the actionscript I want to go through a for loop and set the text of each of these fields... how can I do it? IE,

for(var i = 0; i <= 10; i++){
_root.descriptionX.text = i;
}

where "descriptionX" depends on the value of i.
any help will be appreciated.

View Replies !    View Related
Convert String To Instance Name
I'm trying to write a function where I can use a string variable to reference a movieclip already on the stage.

Specifically what I want to be able to do is:
-get the name of the MovieClip clicked
-convert the name to a string
-change the string to the name of the next movieclip.
-get the x and y position of the "next movieclip"

I've succeeded up to the point where I need to get the x and y position. Everything I've tried only returns null or undefined.

Here's the relevant code:


ActionScript Code:
var counter:Number = 1;

mc1.addEventListener(MouseEvent.CLICK, onClick);

            function onClick(event:MouseEvent) {
                var mcname:String = event.target.name;
//returns "mc1"
                mcname = mc.substr(0,-1);
//returns "mc"
                counter ++;
                mcname = mcname += counter;
//returns "mc2"
                var mcX = mcname.x;
var mcY = mcname.y;
//that last part doesn't work. I'm trying to get the position of mc2 which is already on the stage.

View Replies !    View Related
String To Movieclip Instance Name
Hi,

I have a function to set focus to a movieclip. Something's wrong, not sure what... I'm blinded by this, and need help!



First I'm creating a movieclip container and populating this with movieclips that will make up a menu. Next step is to give focus to the first "tab" initially, and then to have a selecteditem variable that changes as the focus changes...

//Creates an empty movieclip for containing the menu
menu_container = this.createEmptyMovieClip("main_menu_mc", this.getNextHighestDepth());
menu_container._y = 20;

//Counts through the categorynodes_array and adds buttons
//Adds the category name and description to the textfields in "tab"
for (var i = 0; i<_root.categorynodes_array.length; i++) {
var m = menu_container.attachMovie("tab", "tab"+i+"_mc", i);
m.categoryname_txt.text = _root.categorynames_array[i];
m.categorydescription_txt.text = _root.categorydescriptions_array[i];
m._x = 30;
m._y = (m._height+20)*i;

function setTabFocus(tab) {
var tab:Number = tab;
var tab_mc:String = "main_menu_mc.tab" + tab + "_mc";
trace (tab_mc);
if (selectedItem == null) {
//Selection.setFocus(main_menu_mc.tab0_mc);
Selection.setFocus[tab_mc];
} else {
Selection.setFocus(selectedItem);
}
}
setTabFocus(1);
trace(Selection.getFocus());

Pretty please, help me!

View Replies !    View Related
[CS3/AS2.0]MovieClip Instance Name To String How?
Hello there , nice joinin the forum....I have a question for you dear folks!

I would like to pass the name of a movieclip to a string so my attachmovie method can work. what I m doin is :

function createBlocks(slot:MovieClip)
{
...
...
for (var i = 4; i < 10; i++)//lines
{
grid[j] = new Array();
for (var j = 0; j < 9; j++)//columns
{
var bName = "block_" + i + "_" + j;
holderClip.attachMovie(slot, bName, depth);
...
...
}

when I call the above function on a keyframe I call it like :

this.createBlocks(block4);

block4 is the id name of a movieclip in the library.

the problem is that the attachMovie method needs a string as a parameter!

how can I convert that to a string? so afterwards, slot , has inside the name "block4" (with the quotation marks)

View Replies !    View Related
Refer To An Instance As A String?
Is it possible to work with a symbol via a string instance name ? kinda like javascripts getElementById function..?

Thanks!

View Replies !    View Related
[AS3] Class Instance From String?
Hi guys,

Is it possible to create a class instance from a string representation of the package/class?

For example, could I turn the following variable into an instance of MyClass?


ActionScript Code:
var str:String = "some.package::MyClass";

Cheers.

View Replies !    View Related
Converting Instance Name To String To Use?
Hi,
I have a dynamically created movie clip thats instance name will be something like

_root.emptyportfolio.portfolio.button1_mc


i need to find a way of getting the instance name and assigning it to a string so i can retrieve the 1 from it.

thankyou verymuch.

View Replies !    View Related
Referring To Instance Name As String
Before I go into the longwinded version in words, here's what I'm trying to do:

say one instance of multiple mc's is named "main1";
is there a way to script a btn inside of said mc to say something like

on (release){
_root.loadMovie("<<DynamicallyGeneratedNameHere>>.jpg", "emptyClip_mc");
}

where the string inside the carrots, for this example, would be "main1", and of course for all the others would refer to their own mc's instance name ("main2", "main3", etc.)

So now for the longwinded version (if it's even necessary to understand where I'm coming from): I need to have all of my buttons' contents be editable in one fell swwop (and the scripts as well), so the actual scripts will all be the same since all the buttons will be multiple instances of symbols. I would like to make the script within the symbol dynamically refer to different movies (or jpgs) to load. The only way to make that happen would be to use the individual instance names of the buttons in the reference to individual movies. Am I clear? Thanks for any help you may be able to offer

View Replies !    View Related
String To Movieclip Instance Name
Hi All,

Is there a way to convert a string to a movieclip instance?

function buttonClicked(e:MouseEvent) {

var myMc = e.target.parent.name;
trace(myMc.x);
}


i get this error

ReferenceError: Error #1069: Property x not found on String and there is no default value. at MethodInfo-99()


Thanks in advance!

View Replies !    View Related
Can You Refer To A Instance Name By A String?
i have a program that names various instances like this:
this._name="Car"+count;
count+=1;

now what i need to do is refer to these instances in a while loop:


i.e
_root.Car+""+newcount+""._x=7;
newcount+=1;


thanks

View Replies !    View Related
Can Trace String But Cannot Set String To Variable
Hi,

I am importing a some text values from a text file and then trying to pass this value via a function

I can TRACE the text value successfully but cannot set it to a variable.

************************************************** **************
function test(){
var aTestVariable

myData = new LoadVars()
myData.load("thenews.html")
myData.onLoad= function(success){

if(success){
trace(myData.Title); //THIS WORKS
aTestVariable = (myData.Title);
}
}
return aTestVariable
}

function testFunction() {
trace(test()); //THIS DOES NOT WORK!
}
************************************************** **************


Can someone please tell me what is wrong with this:


trace(myData.Title); //THIS WORKS
aTestVariable = (myData.Title);

HELP!

Rich

View Replies !    View Related
PHP String To Flash Array To Instance Name
This is really anoying me.

I want to use date's that are stored in a SQL database to set MC's in my flashsite to visible false or true.

If I define an array in flash it's no problem.
datumArray = new Array(sep2,sep3,sep4,nov12);
for (var i = 0; i < datumArray.length; ++i){
datumArray[i]._visible = false;
}

created Array is like this;
Variable _level0.datumArray = [object #1, class 'Array'] [
0:[movieclip:_level0.sep2],
1:[movieclip:_level0.sep3],
2:[movieclip:_level0.sep4],
3:[movieclip:_level0.nov12]
]
Variable _level0.i = 4

but the datumArray comes from SQL using PHP. I tried lost os things but always end up with an array that uses quoted names in stead of instance names. Example;

PHP returns datums="sep2,sep3,sep4,nov12"

AS
datumArray=this.datums.split(",");


created Array is like this;
Variable _level0.datumArray = [object #1, class 'Array'] [
0:"sep2",
1:"sep3",
2:"sep4",
3:"nov12"
]
Variable _level0.i = 4

if I leave the "" on my PHP returned string out, Flash won't create the array.

It's really driving me crazy. Can anyone tell me how to create an array that can be used as instance names....so with values like, [movieclip:_level0.sep2],

View Replies !    View Related
Access Instance Name From Dynamic Txt String...?
I'm accessing a string (which is also an instance name) from a text file which is loaded on to a dynamic text box. Now I want to access the corresponding movie clip with the same instance name as of that string. So, if you actually look at it, the code would look something like as follows,

Considering the following:

- "varCheck" is the instance name of the dynamic textbox.
- "mc1" is the string it contains AND the instance name of an existing movie clip.

My mission: To play the 2nd frame of "mc1" movieclip...

Presumed code,

_root.varCheck.text.gotoAndPlay(2); <-- this is wrong but it shows what I'm trying to do

So, help anyone?????

View Replies !    View Related
Convert String Into MovieClip Instance Name
I want to do something like -
Code:
var theMC:String = "myMovieClip";
value(theMC).getBytesLoaded();
That is, I have a string of movieClip names, and want to get an object var with the same name.

How do I convert a string into an object ?

Thanks

View Replies !    View Related
[CS3] Refering To An Instance With A String From An Array
have a variable that will have a differn't string value depending on a random event. I want to use the string that is passed to that variable to move an instance on the stage. Is there someway to do this? I will attach the code to kind of show what im doing. To explain the code a little more the goal of it is to create an array of 4 cards and shuffle them. Once they are shuffled I want to select the first card in the array and move it.
Attach Code

// important packages
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.*;

dealBtn.addEventListener(MouseEvent.CLICK, deal);


function deal(event:MouseEvent):void
{

var cardNames:Array;
var cardValues:Array;
var card1:String = new String();

cardNames = ["aceHeart", "twoHeart", "threeHeart", "fourHeart"];
cardValues = [1,2,3,4];


var shuffled:Array = new Array();
var randomNum:Number;
var randomNum2:Number;
var store:String;
var SwitchValue:Number;
for (var i:uint = 0; i < 3; i++)
{
randomNum = Math.floor(Math.random()*3);
randomNum2 = Math.floor(Math.random()*3);
store = cardNames[randomNum];
cardNames[randomNum] = cardNames[randomNum2];
cardNames[randomNum2]= store;
}

cardNames[1] = card1;
card1.x = 252;
card1.y = 256;

View Replies !    View Related
[AS2] Create Instance Of Class From String
I can't figure this out. I want to create a class instance based on the string variable passed to it:


Code:
var className = "someClass";
var sc = new className(); // fail
var sc = new _root.className(); // Throws no errors, but doesn't create a class instance
I searched the forums but the only true solution was as3, and this is as2. Any ideas?

View Replies !    View Related
Force Instance Of A Class With A String
Hi,

I've been trying for a while to create a full framework of website menager that can menage different pages with modules and templates via Flash and I've hit a wall with the dynamic class importing.

First the code:


ActionScript Code:
import packages.site.templates.*;

public function changeTemplate(newTempObj:String, newPageName:String):Void{
        if(newTempObj != isLoaded.template){
            trace(newTempObj+" = "+typeof(newTempObj));
            trace(packages.portfolio.templates[newTempObj]);
            addTemplate(newTempObj,"tFormulaire", newPageName);
        }else{
            trace("template already exists!");
        }
    }

The value of newTempObj is a string, the name of a Class named "Temp_Home".

The problem is that when I trace packages.portfolio.templates[newTempObj], the compiler doesn't import the class into the SWF. However, when I trace packages.portfolio.templates["Temp_Home"] it does. newTempObj is a string and has the right value... but the compiler still doesnt work and I can't just force-type the value as it is parsed from an XML.

Thanks for any help.

View Replies !    View Related
Matching A String Literal With An Instance Name
Is there any way to get the ActionScript to load the variable then act on a matching instance name? For example I am creating a dbase driven gaming site. When a review is from Gamecube I want a gamecube logo to pop up in the graphic. I have the logo named "gamecube" as the instance, and the variable read in also is "gamecube" from the systems table in the database. Now I wanted to link the String to the instance, IE "system"._visible = true; Is there any way to do this, because there are many system logos, and instead of having 10+ if statements, I wanted just one that would just turn on the visibility of the instance that matches the String. If anyone can help I would greatly appreciate it.

View Replies !    View Related
Return Class Instance As String
Is there anyway to include a function or overrite something in a class that'll output a custom string when the object is called as a string?

So for example if I created a class named "myClass" and I instantiated it:

Code:
var myObject : myClass = new myClass();
When I:

Code:
TextControl.text = "blah blah, " + myObject;
myObject is getting casted as a string. Normally it would output:
"blah blah, [object myClass]"

Is there a built-in function that recast the object as string? Is there anyway for me to change that string output? I know I can just make a public toString() method in the class or something, but just wondering if there was something better.

View Replies !    View Related
Converting A String To A MovieClip Instance
hi there guyz,
I needed your help on flash action script…

I wanted to know whether there is any way to convert a variable/string to a movie-clip object/instance?

I know we can use toString() to do it the other way around… But I need to extract a value from an array [which has values pushed into the array that are movie-clip instances and its x & y positions] and then convert this extracted value into a movie-clip instance to set its properties to change the x & y positions of the movie-clip. There seems to be a type mis-match coz the setProperty() returns an undefined value.

M not able to find anything relevant or even close to doing such a thing on the net… if u know… do let me know… its kinda really really urgent… will really appreciate your help.

Thanks in advance,

Regards,

Kavini

View Replies !    View Related
Convert String To An Object Instance Name
Hey there,

I'd like to append multiple strings in order to create an instance names. The code is placed below:

// I have 3 buttons contained in a MC with the instance name "container"
// I've created an array of the button instance names
var myArray:Array = new Array (button1, button2, button3);
// I'm using a "for" loop to automate the process
for (i = 0; i < myArray.length; i++){
// Creates a string of the path from root level to the button
var myArray:String = "container." + myArray;
// Trying to convert the string into an object and also abbreviate the path from "container.button1" to "button1"
var myArray:Object = new Object();
// Change all the buttons alphas to 100
myArray._alpha = 100;
}

thanks in Advance!
Susan

View Replies !    View Related
(AS2, OOP) Create An Instance Of A Class, By Name (String)?
In as simple an example as I can think of, I have two classes: Dog and Cat. Both are subclasses of Animal, in this stupid example...

I know how to create instances of both, however I don't know how to dynamically create them by name from a string.

It would be something like...

function addAnimal( type:String ):Animal {
return new [type]();
}

Thanks in advance.

View Replies !    View Related
Gettign Mc Instance Passed Through A String.
Hi, this is my first post to this forum
I'm trying to dynamically pass different movieclip names as strings to a function in order to tween them but im stuck with making flash understand that the mc names im passing are actual movieclips in the library.

Code:

public function receivedFromJavaScript(mc:String):void {
var tMC:Class = getDefinitionByName(mc) as Class;
var newMc:MovieClip = new tMC() as MovieClip;
Tweener.addTween(newMc, {alpha:1, time:0.2, transition:"linear"});
}
So when I pass "MyMC" to the function abobve i recieve following error:
"ReferenceError: Error #1065: Variable MyMC is not defined."

Could anyone please point me in the right direction with this one?

/I

View Replies !    View Related
How To Store A String Plus A Variable In A Dynamic Text Variable?
Hi,

I've got a dynamic text field with the instance name rightAnswer_txt.

I declare the variable in the frame it resides in, with the following code var rightAnswer_txt:String = "";

Then, when I want to populate it using the following code:

rightAnswer_txt.text = "You scored " + rightAnswers;

the script comes out with an error saying ...

**Error** Scene=Scene 1, layer=actions, frame=7:Line 15: There is no property with the name 'text'.
rightAnswer_txt.text = "You scored " + rightAnswers;

Any idea what this means anyone please?

View Replies !    View Related
How To Convert String To Object (movieclip Instance Name)
this is a function on my _root :


function callMsg(title,msg,btn) {
trace("_root.msgBox() is called");

_root.x += 1;
var newName = "x"+_root.x;
duplicateMovieClip("_root.msgBox",newName,_root.x) ;

//////////////////////////////////////////////
//Need to call function startMsg() in the created movieclip
//////////////////////////////////////////////

var xx = (Stage.width/2 - _root.msgBox._width/2);
var yy = (Stage.height/2 - _root.msgBox._height/2);
setProperty(newName,_x,xx);
setProperty(newName,_y,yy);
}


with that i added a line

_root.newName.startMsg();

but it wouldnt work, i thought the reason must be "newName" is a String hence it wouldnt refer to a _root.String but looking for a _root.object


example if newName is "x1", the duped movie clip would be named x1 too
hence i need to call out :
_root.x1.startMsg();

qns is how do i get it to refer newName as a movie clip ?
thx in advance, btw whats the difference between depth and level ? and can i delete my own post here ?

View Replies !    View Related
Retrieve Full Class Name (string) From An Instance
Hello,

Ok I wonder if it's doable.
Is there a way to retrieve the full class name (package name) of a class from one of its instance???

Thx much.

View Replies !    View Related
String + Function Parameter = Existing Instance Name
I am doing some form validation and am trying to create a function that will check the text of a TextInput object then change the color of some adjacent dynamic text to indicate that the field has been left blank. I am passing the instance name of the TextInput to the function then I want to attach the string "Text" to the end of the instance name to create the instance name of the adjacent dynamic text field (e.g. coachFirstName --> coachFirstNameText). I am sure this is doable, but am having a hard time getting the right syntax. Here is the code I am using. Thanks!:







Attach Code

var myFormat:TextFormat = new TextFormat();
myFormat.color = 0xA05324;

function checkNaN(fieldName){
if(fieldName.text == "") {
catVar = fieldName + "Text";
catVar.setTextFormat(myFormat)
//fieldName + "Text".setTextFormat(myFormat)
}
}

checkNaN(coachFirstName)

View Replies !    View Related
Possible? Address Dynamic Clips By String Contained In Instance Name
Hi,

Is it possible to address any clip whose instance name contains a string?
I am ultimately trying to create a hitTest to see if any of dynamically created clips are clicked on - these clips are created using attachMovie, and are named like attachMovie(...,"string" + number,...) . Is there any way to evaluate a clip to see if it contains "string" in the instance name?

I know what I'm trying to achieve can be done by looping through an array that is filled by these dynamic clips upon their creation, but the loops really slow things down!

Thanks in advance.

View Replies !    View Related
How Do I Convert A String Variable Into A Number Variable?
How do I convert a string variable into a number variable?

Thanks in advance.

Garry

View Replies !    View Related
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

View Replies !    View Related
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?

View Replies !    View Related
Instance Name = Variable :: Can This Be Done ?
Hi all, I am doing movie that will read an array and will build text fields accordingly. some of these fields will be Dynamic and some will be Input fields. the number of fields is different for each time the movie will run. I want to make a loop that will create a field each time:

Basically:


while(count<5){
_root.createTextField (textField[count],1,100,100,100,20);
count=count+1;
}

The problem is that I need to assign another Property to the text field in order to determine whether it’s an input or dynamic field :

_root.textField[count].type = variable

as you might know this will not work because this line will not get a variable name as an instance name. Is there a way to put a variable as the instance name ? you guys have other ideas ?

Thanks,
LeoBeer.
[Edited by LeoBeer on 08-08-2002 at 06:10 AM]

View Replies !    View Related
Can An Instance Name Be A Variable?
I think I can solve one of my issues if I can put a variable in the box where you label the instance. I know you can call an instance name by a variable but can you actually put the variable in the label box?

Thanks

View Replies !    View Related
Using A Variable As An Instance Name?
Ok here's my issue,

I have a ton of mc's rolling around on the stage
I want to create a button to rotate the last one i clicked on.

can some one tell me if i am thinking on the right track and if so how i script this thing.

---on the first frame of my movie

lastpiece = "one";

---each of my doohickys have:

on (press) {
startDrag("");
}
on (release) {
stopDrag();
_root.lastpiece = "one";
}

---Where "one" is the instance name of the mc in question

---my button to rotate

on (release) {
lastpiece._rotation = lastpiece._rotation+45;
}

Obviously this is not working..........
do you see what i'm trying to do?
can i do this at all?
how?

any advice appreciated
shoeshine

View Replies !    View Related
How Do I Put A MC's Instance Name In A Variable?
How do I do this?:

_root.car_currently_driving = this_mcs_instance_name;

Thanks

View Replies !    View Related
Instance Name In Variable
Simple question, I want to store an instance name in a variable.

I did it like that:

var currentMovie = "test";

I want to do some action when a button is clicked, I tried it like this:

_root.currentMovie.gotoAndStop(2);

That must not be the correct syntax cause it ain't working. If I do a trace of _root.currentMovie, it returns test...

What is wrong with my syntax??

Thanks in advance!

View Replies !    View Related
Variable Using An Instance Name?
At least I think that's what I want...

I have a movie clip that is used 12 times on a page, but I want each one to load a different jpg.

The code I'm using is:
Code:
_root.createEmptyMovieClip("container", 1);
container.createEmptyMovieClip("mc", 1);

container.mc.loadMovie("images/101.jpg");
container._x = -50;
container._y = -50;
but it won't work because the container and mc are the same name. This thing only works once because of that.

My images are called 101.jpg, 102.jpg, 103.jpg, etc. And my instances of each movie clip are also called 101, 102, 103, etc.

So I was hoping to somehow use the instance name of the mc as a variable in the script so there is no duplication with container and mc names, and so that a different jpg is loaded in each mc.

Can someone help me out on how I would do this?

Thanks!!!

View Replies !    View Related
Variable Instead Of Instance Name?
i want to be able to have a variable used instead of having to type out the actual instance name of an object. i tried doing something like _root._root.instanceVariable.stop();
and
_name._root.instanceVariable.stop();

but it's not recognizing it as a variable, i think it's looking for an object with the instance name of 'instanceVariable'.

i'm sure there's a way to do it, but i just don't have a clue how. please be able to help me.

thanks,
jason

View Replies !    View Related
Is This A Variable Or An Instance?
Hi, I'm trying to disect this script but am having trouble with a line. The code creates 2 string arrays. It then loops through each array and creates movie clips for each element. These movie clips house buttons. The great thing about this, is that it is a procedural interface. The number of buttons and sub buttons is determined by the length of the array. This is the code. The line that is troubling me is commented on the side.

onClipEvent (load) {
// -- set up names of main items here
// -- you can add as many new sections as you want (or your computer can handle)
mainSections = new Array("Info", "names", "titles");
// -- one array for each main Section -
subSection0 = new Array("finance", "commerce", "trade");
subSection1 = new Array("Jack", "John", "Mike", "Elmer","Sheela");
subSection2 = new Array("Presidents","Accountants", "Techies" );
// --
// --
// -- build the main buttons
for (i=0; i<mainSections.length; i++) {
attachMovie("mainButton", "main"+i, i+300);



myButton = this["main"+i];//THIS IS THE LINE

//I don't understand the syntax with the square brackets following
//the "this" keyword. What does it signify?
//Is myButton a variable or an instance name? I can't find it in the library.
//I can post an fla if needed.



myButton.subs = this["subSection"+i];
myButton.button.value = mainSections[i];
myButton._x = (myButton._width + 25) *i ;
// -- build subsection buttons for each main button
for (x=0; x<myButton.subs.length; x++) {
myButton.attachMovie("subButton", "sub"+x, x);
mySub = myButton["sub"+x];
mySub.button.value = myButton.subs[x];
mySub.button.outYpos = myButton._height + 15 + ((mySub._height + 15) *x);
}
}
// -- function that opens the subsection on rollover
function openSubs (target) {
for (i=0; i<this[target].subs.length; i++) {
subMenuCounter = 0;
this[target]["sub"+i].button.newY = this[target]["sub"+i].button.outYpos;
currentOpen = target;
}
}
// -- close subsections function
function closeSubs (target) {
for (i=0; i<this[target].subs.length; i++) {
this[target]["sub"+i].button.newY = this[target]["sub"+i].button.oYpos;
}
}
}
onClipEvent (enterFrame) {
// -- a timer that closes the menus after a certain amount of time
subMenuCounter++;
if (subMenuCounter>100) {
closeSubs(currentOpen);
subMenuCounter = 0;
}
}
onClipEvent (mouseUp) {
// -- this closes the curently open submenu if the user clicks outside of the menu
if ((this.hitTest(_root._xmouse, _root._ymouse)) || (!this.hitTest(_root._xmouse, _root._ymouse))) ; {
closeSubs(currentOpen);
}
}


nubie

View Replies !    View Related
Variable As Instance Name
Okay, let me begin by saying that if this is a stupid rule that I should know better than to violate, I apologize... Here's the deal:

I have a menu of 4 buttons, and 4 pages in my main movie under the following movie-clip instance names:

home_mc
basketball_mc
baseball_mc
football_mc

Each movie clip has 2 labeled sections ("in", and "out"). My goal is that when you click a menu button. The current movie clip will play the "out" animation prior to loading the "in" animation of the new page selected.

This is the complicated way of saying that I want an advanced transition.

I decided to tackle my problem the following way. I created a global variable "currentPage", and set it to "home" on the first frame of my movie. Each time you press a menu button, depending on the button, the following AS will run:

Basketball Button

Code:
on(release){
var newPage = (_global.currentPage + "_mc");
_root.newPage.gotoAndPlay("out");
_global.currentPage = "basketball";
}
As you can see, I have also created a local variable "newPage". This variable combines the currentPage variable with the "_mc" ending to achieve my instance name of "home_mc".

The next line is intended for the home_mc movie-clip to run the "out" animation.

The last line sets my currentPage variable to "basketball", for the purpose of the next piece of actionscript which can be found on the LAST frame of the "out" animation inside the home_mc movie-clip.


Code:
var nextPage = (_global.currentPage + "_mc");
_root.nextPage.gotoAndPlay("in");
This then sets another variable "nextPage" equal to my other movie-clip "basketball_mc". The next line then makes the call for my nextPage "basketball_mc" to play its "in" animation.

I hope I didn't lose you during this explanation, I was trying to be as clear as possible... I debugged and traced everything. My variables work just fine...

The problem is the call: _root.nextPage.gotoAndPlay("in");

I don't think actionScript likes me using a variable where an instance name is intended, even if the variable is set to equal that instance name.

View Replies !    View Related
Variable As An Instance Name
can a variable = instance name
What i am atemting to do is call up random locations by MC and using there X and Y make a second MC go to that location.

and if so can i get the x and y of a MC if i us the variable name it keeps coming up as undfined.

ActionScript Code:
onClipEvent(enterFrame){

    _root.xdiv = (_root.target_x - _root.circle._x) / 20;
 _root.ydiv = (_root.target_y - _root.circle._y) / 20;

    _root.circle._x += _root.xdiv ;
    _root.circle._y += _root.ydiv ;
   
    if (_root.circle._x <= _root.target_x && _root.circle._y <= _root.target_y){
        i = Math.ceil (Math.random()*4);
        _root.target_x = ("Targating"+i,_x);
        _root.target_y = ("Targating"+i,_y);

    }
}
in side the MC on first frame have this

ActionScript Code:
i = Math.ceil (Math.random()*4);
_root.target_x = ("_root.Targating"+i,_x);
_root.target_y = ("_root.Targating"+i,_y);
and second frame

ActionScript Code:
stop();

View Replies !    View Related
Copyright © 2005-08 www.BigResource.com, All rights reserved