IDE :: Refering To An Instance Name By Variable?

Sep 10, 2009

I am trying to create a game in Flash. There are 43 spaces of irregular shape in the game and I already know the X and Y location. I defined them as a class which extends movie clip, I put them on the main timeline to start and I gave them all an instance name. I want to initialize them when I am starting a new game. I defined methods to set and get the properties, those methods work when I use the instance name, but many of the spaces share the same properties. The instance names are all I+some numberm I1, I2, I3. When I try to use a variable name such as space_Id = ("I" + i) to reference the instance name I get an error "Call to a possibly of undefined method. I tried the old actionscript 2 solution of putting an eval function eval (space_id) in front of the method but that didn't work either. It resulted in the same error plus a warning. I1.My_Method (); // works but it would require 20 or so blocks of almost identical code

var space_Id:String = "I1";
space_Id.My_Method (); // doesn't work
_root.space_Id.My_Method (); doesn't work

[code]....

View 7 Replies


Similar Posts:


ActionScript 3.0 :: Variable Refering To Type Of A Class?

Jun 17, 2009

ve faced a problem. I have a super class called "Plane" which has subclasses called "Fighter" and "Bomber". each of these subclasses have a bullet type "Cannon" and "Bomb"Now I want the to send a reference of the bullet type to the super class, because bullet creation is handled there and I want to let the super class know which bullet type to create.Ofcourse I could pass a string, I just ant to know if there is a better way, like storing a class type in a variable?

View 2 Replies

ActionScript 2.0 :: Refering To Variable LoadVar Dynamically?

Mar 31, 2004

I am reading a file with certain user defined variables like &x=30&y=50&z=100Lets the variable is caught in a function as argument myVarnow depending on the variable the user passes I need to fetch the value. ie if the user passes x i need to read the value of x.lso keep in mind i dont havehow the user has named his/her variables.What i need to do it get the value of that variable by using loadVar.this.myVar;As such it gives me undefined. There is text present in 'this' myVar represents 'x'I have tried eval(this.myVar) as well as this.eval(myVar) but in vain

View 5 Replies

ActionScript 3.0 :: Create New Instance() When Instance Is A Variable?

Feb 12, 2012

I have a base class I've used on 6 different MC's. Then when I use these MC's my function runs an if statement to check which one to add.

if(id=design) var obj = new design();
if(id=team) var obj = new team();

I want to make it a bit more dynamic and use the id:String to evaluate which new instance to create.

ActionScript Code:
public function loadChapter(id:String):void {
var obj = new instance_of( id )();
}

View 5 Replies

ActionScript 3.0 :: Variable Of Null Value Assignment To A Variable Or Instance Flash?

Jan 7, 2010

As we know whent here is no such variable of null value assignment to a variable or instance flash throws this kind of Error.In one of my Application i need to get more flashVariables, They may or maynot come as FLASHVARS. But when i miss any variable flash thows this error as an alert box. is there any simple solution to avoid this kind of issue
 
when i use try,Catch statement the issue will not come, But i don't like to write Bunch of try,catch statement for all this kind of variables.

View 4 Replies

ActionScript 3.0 :: Refering To A Specific Child?

Feb 1, 2010

In my program, I have multiple children of the same movie clip. Each movie clip has a text field inside it which shows data relating to that movie clip. However, I need some way to update that data at run time to reflect changes that may be taking place. My problem comes to, how am I supposed to target that specific child of this movie clip since there are around 40 of them on the stage at the same time?

View 3 Replies

ActionScript 2.0 :: Refering To Multiple Objects?

Feb 22, 2010

this problem has been solved. i only had to remove the "else{ return false;}" bit. I'm an animator who kinda wants to be able to do some actionscript but who isn't that good at it. atm I'm trying to make something which contains a hitTest() which should check if my movieclip (doll_mc) is touching any instance of "ground".

My attempt to make a code for this has dramatically failed and this is all I managed to make which does make a bit of sense: var nrOfgrounds:Number = 2; /*this is the number of instances, which should be kept up-to date with the project, of course.*/

setInterval( groundCheck(doll_mc), 25);function groundCheck(obj:MovieClip):Boolean{ /*returns boolean groundCheck(<objectName> [in this case, "doll_mc"]); */ for (var i:Number = 1; i <= nrOfGrounds; i++) { /* <- i've got a feeling like this bit ain't working properly*/

[Code]...

just to see what would happen, and yes, this time groundCheck(doll_mc) would only be true when doll_mc was touching ground2_mc, but not when touching ground1_mc. therefore there must be something wrong with that one bit of code, but I can't figure out what!

View 7 Replies

Professional :: Refering To Line In Text Field?

Jun 21, 2011

probably it is very simple, but I couldn`t find anything in the net.How can I take specific line from text field. In my case, it will be number and I`m planing to use parseInt. on that string

example:
line1 = 001
line2 = 002

[code].....

View 3 Replies

ActionScript 3.0 :: Refering To Multiple MovieClips Using Loop

Jul 5, 2010

I simply want to be able to access 3 already created, but not yet added movieclips using a loop. I've tried a few code combination but can't figure out the syntax.[code]

View 2 Replies

ActionScript 2.0 :: Dynamic Naming TextField And Refering It?

Mar 8, 2004

I am generation a textField by_root.createTextField("some"+randomNumber,1);Now I want to assign some text to the textField, how do I refer to it???

I tried using a variable first like
var myText="some"+randomNumber;
_root.createTextField(myText,1);

[code].....

View 3 Replies

ActionScript 2.0 :: Dynamic Naming TextField And Refering It ?

Mar 8, 2004

I am generation a textField by

_root.createTextField("some"+randomNumber,1);

Now I want to assign some text to the textField, how do I refer to it? I tried using a variable first like

var myText="some"+randomNumber;
_root.createTextField(myText,1);
myText.text="something";

it doesnt work it gives me an error

View 3 Replies

ActionScript 1/2 :: Refering To A Class Imported On The Root Timeline?

May 22, 2009

This is probably ueber basic, but I don't know how to do it. I am importing tweenlite on the root timeline like this: import gs.TweenLite;

I now want animate things in other MCs. I tried something like this, but it did not seem to work.parent.TweenLite.to(text1, 3, {_alpha:100, overwrite:0});

View 5 Replies

ActionScript 3.0 :: Refering Variables Into A Parent / Main Movie

Aug 4, 2010

I've build several movies which all work fine, but ultimately they need to run inside a Main movie which acts as a holder for the various child movies which load into it.Everything is working fine but not when they're loaded into the main movie. The main problems seems to be that the main movie has common component which relate to all the loaded child movies.Consequently the main movie has several instances - but how do I refer back to them in the child movieclips?I can't get the child movie clips to compile if I remove the references but ultimately the child movie clips need to speak to instances and functions in the main movie.Also, I've got a global function to hold the global variables but this method seems frowned on. But I need the global variables all the time and in all the movie clips.

View 3 Replies

Flash :: "Instance Name At Design Time" Vs "Instance Name Added Dynamically" Vs "Variable Name In Related Class"

Nov 4, 2011

Say i have a movieclip named a_Mc ( ClassA ) I have a sub-movieclip named b_Mc ( ClassB )

CASE 1: Accessing the sub-movieclip b_Mc which is already present inside the a_Mc movieclip

( Since Flash IDE has "Automatic instance naming" OFF )

ClassA mentions the name of b_Mc as => var b_Mc:MovieClip;

NOTE HERE: That the variable name MUST BE same as the name of the instance on stage.

So i can access it as : trace( a_Mc.b_Mc);

[Code]...

View 1 Replies

ActionScript 2.0 :: Use Variable For An Instance Name?

May 6, 2011

Ok, I've been at this for 2 days now, and really need some assistance. It seems like it should be so simple!

The part that doesn't work [code]...

Then that button in the root should be able to take the value that is in the variable "critter_pressed_new" and use that as the instance name, to make that particular mc go away.

View 2 Replies

ActionScript 3.0 :: Using A Variable In An Instance Name

May 31, 2010

Simple question: I'm trying to use a variable to call on different instance names:

[Code]...

The code in red is the issue in question. In this example, I'm trying to add a child called "pic_2", with the number two called from the variable "picCaller"

View 16 Replies

ActionScript 2.0 :: Instance Name By Variable?

Jan 17, 2009

I have multiple inputs which I would like to limit the input on. Not limit to number of characters but limit to the actual input box. The problem is the limit script is not reading the variable I am sending to the function and is returning as undefined.

ActionScript Code:
function Limit(SetText){
oKey = new Object();
var __text0:String = "";

[code]....

View 0 Replies

ActionScript 2.0 :: Using Variable In Instance Name

Dec 3, 2009

I am trying to create an animation that will cycle through letters (each of which have an instance name) by using a loop. I have a variable which it outputting the numbers i need if just used in a tract but i want to add it to the end of the instance name so that each instance scales one after the other. Any way of delaying each one by a few few seconds (or milliseconds if I remember the acrionscript unit of time correctly).

View 3 Replies

ActionScript 3.0 :: Using A Variable For An Instance Name?

Feb 1, 2010

Basically I am having errors when trying to use a variable to set my instance name.

Here is the code:

ActionScript Code:
var i:Number = 1;
["button"+i].transform.colorTransform=myColorTransform; //doesn't work
button2.transform.colorTransform=myColorTransform;//works

'i' will always carry the button number.

I've tried all the methods I can think of so I am hoping that one of you can give me a hand, if I can figure this out I can probably save a few hundred lines of code in an app I have just started on.

View 3 Replies

ActionScript 2.0 :: Get An Instance Name And Use It As A Variable?

Jul 19, 2006

How do I get the name of an instance and use it as a variable?

Something like:

my_name = getInstancename(this);

View 1 Replies

ActionScript 3.0 :: Using A Variable In An Instance Name?

Nov 17, 2010

I'm trying to use a variable to call on different instance names:

var picCaller:uint=2;
material_mc.addChild(pic_""+picCaller+"");
 
The code in red is the issue in question.  In this example, I'm trying to add a child called "pic_2", with the number two called from the variable "picCaller"

View 2 Replies

ActionScript 2.0 :: Use A Variable As The Instance Name?

Jun 4, 2008

I have a static shopping centre floorplan with movieclips for each unit. There is also a list of the stores fed in from an XML page. When they rollover either the unit on the floorplan or the storename in the list, a little information panel appears for each store. All that's fine.

The problem is I want the corresponding unit to highlight when the text is rolled over and vice versa, but just can't seem to get it to work!!! You would think that would be the easy part. I have a variable - currentunit - which I pass from the onRollover. This is the same as the corresponding instance name of the floorplan unit.

I though I could use something like

[currentunit]gotoAndPlay("_over");

View 6 Replies

ActionScript 3.0 :: Use Variable Instead Of Instance Name

Oct 5, 2009

Basically, I'm trying to loop through my sub menu buttons to see if they're on a certain frame. My question deals with an if statement inside a for loop:

if (MovieClip(root).subMenu1.currentFrame == "16") {
MovieClip(root).subMenu1.gotoAndStop("out");
}

Is it possible to replace the instance name (subMenu1) with a variable? I tried just replacing it but that didn't work. I also tried adding plus signs around it and that didn't work either.

View 3 Replies

ActionScript 2.0 :: Using Variable In Instance Name?

Dec 3, 2009

Im trying to create an animation that will cycle through letters (each of which have an instance name) by using a loop. I have a variable which it outputting the numbers i need if just used in a tract but i want to add it to the end of the instance name so that each instance scales one after the other. delaying each one by a few few seconds (or milliseconds if i remember the acrionscript unit of time correctly).

View 1 Replies

ActionScript 2.0 :: Using A Variable For An Instance Name?

May 6, 2011

Ok, I've been at this for 2 days now, and really need some assistance. It seems like it should be so simple! Tried some other web resources but so far no luck.

The part that doesn't work:

Code:
on(release){
//None of these work:

[Code]....

which now makes the variable of "critter_pressed_new" have the instance name of the movie clip in it (which, would be _level0.critter_launched_01 or 02).

Then that button in the root should be able to take the value that is in the variable "critter_pressed_new" and use that as the instance name, to make that particular mc go away.

View 3 Replies

ActionScript 3.0 :: Referring To Instance With Variable?

Jul 23, 2009

I'm trying to access an instance by using a variable but when I try to manipulate a property to the instance (by referring to it with a variable) it only recognizes it as a string... for instance... (pun intended??)
public var prevbutton:String = "btn1";
trace(["page"+prevbutton]);
// which traces - pagebtn1
trace(pagebtn1);
// which traces the instance class - [object btn1pageclass]
I want to call the instance by using a variable... how do I do this?

View 11 Replies

ActionScript 2.0 :: Flash8 Variable From Instance Name?

Sep 5, 2009

I've got these 150 buttons on my stage which all do the same thing. They test their value against myVariable to see if there's a match. If there is, it's a right answer and the user gets a point. The myVariable may be anything between 1 and 150. I have my button code on a single frame now but I'm looking at duplicating it 150 times (1 for each button instance). This seems a wasteful way of doing things. Is there any way I can extract a variable from the instance name? The buttons named btn1~btn150.

Is there any way to:
btn 1~150 onRelease
var newVariable = [instance name - "btn"]
I guess this requires some way to listen for an instance name.

View 3 Replies

ActionScript 2.0 :: Instance Name As Variable - Flash 8?

Oct 12, 2010

I have an application I am developing, a part of which involves a number of icons on a page - when you roll your mouse over an icon, the movie moves forward a frame, and a text area is populated with text, fed from a php file (which pulls data from a MySQL database). Each icon pulls in a different value, depending on the values in the php file.

I have this working a treat - see code below. The only problem is I need to create a seperate button / mc for each icon with the appropriate references on - in the code example below, the icon populates message.text - this.message2 - message2 is a value in the php file. So the next symbol would be message3, etc.

on (rollOver) {
myData = new LoadVars();
myData.onLoad = function() {
message.text = this.message2;

[code]....

I will need a large number of these icons, all with different values, so I would like to create a generic button that looks at it's instance name, and uses this for the numbered variable - i.e. the 2 in "message2".

View 2 Replies

ActionScript 2.0 :: New Sound Instance With Variable

Dec 20, 2010

var sound_[infotoload]:Sound = new Sound();
This doesn't work. I want sound_01 sound_02 sound_03 sound_04

View 1 Replies

ActionScript 1/2 :: Appending Variable To Instance Name?

Jul 22, 2010

I am trying to get all the button instances to become invisible on the screen. They are named img1 to img30. I thought of using a while loop to quickly run through them. The code within img1 button is:
 
var i:Number = 2;
while(i<=30) {
img2._alpha = 0;
i++;
}
 
The problem is how do I append the i after img, to replace the 2? so that the code runs through img 2 to img 30. I know the answer might be simple

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved