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
Similar Posts:
Aug 21, 2009
I want to declare a variable on the main timeline that can be called from anywhere in my movie. So, _global var should be the right approach. I want to declare a movie clip 'MC1' "open", or "closed" so that when it is revisited, my flash file knows the user has been there before and performs a different task from the one it does when 'MC1' was first encountered. So, i need a 'if' statement to run from the variable, when the playhead encounters the movieClip.
[Code]..
View 2 Replies
May 29, 2009
I'm trying to make something that will show up in a dynac text field something like this:"[variable1] text text text [varibale2] text text text"I've linked the dynamic text field to a variable "resu" and set it to:var resu = variable1 + "text text text text" + variable2 + "text text text"The only problem is that when I make the variables random, they don't change
View 1 Replies
Jun 5, 2009
I have 4 Mc's on the stage, and they have instance names 'mc1' - 'mc2' etc.The MC's have links in them (they are kind'a navigation items) and i need to change the functions of the 'rollOver, and mouseDown events', but keep the MC's the same.The MC's are referenced by instance name and given functions in the first few frames of he movie. for example
---------------
mc_1_0.onRollOver = function() {
if (_root.mc_1_0._currentFrame == 1) {
[code]...
Now, what i want achieve is to change the instance names of the MC's (mc_1_0 for example) so that when the user interacts with this MC on the stage, they are taken to locations of my choice (and the actions of another MC), by switching the instance names. IE, i want to change the instance name of 'mc_1_0' to 'mc_2_0' at runtime, BUT i want to do it with a variable from a .txt file.i would need to start with a script that looks for the MC with a certain instance name
-- look for instance mc_1_0, and then change the instance name to 'mc_2_0'
The effect would be that the user would instigate the same actions, regardless of which of the two MC's they rolled over.Maybe i could call the instances initially 'MC_1_Temp' and 'MC_2_Temp' etc: and then i would need a script to change them to 'mc_1_0' and 'mc_2_0' at runtime.SO in the text file i would need something like this
--------------------------
&MC_1_Temp_name=mc_1_0&
--------------------------
this way the behaviour of the MC on the stage wil take on the functions of another MC.should i be looking at something like this placed on the MC.....
onClipEvent(load){
//make this instance called - var = MC_1_Temp_name
}
View 3 Replies
Sep 11, 2009
I've read on the net that actionscripting from the action layer will result in a more readable file once published, as apposed to attaching onClipEvent functions which slow down readability.
For this reason I am trying to add variables to a MovieClip I have on the stage with an Instance Name of Player. However I wish to assign the MovieClip variables from the actions layer using the MovieClips Instance Name.
[Code].....
View 5 Replies
Jul 10, 2008
I'm building a platforming game using AS2. I just got collision detection working between my character and multiple instances of an object. the different collisions (top, left, right, and bottom of platform blocks) are determined by a single symbol with 4 instances named for the different sides. this is good if i only want to have one block. is there a way to reference the symbol name in the actionscript or to have multliple instances of the same name to actually work?
View 1 Replies
Apr 29, 2009
Is it possible to return the index of the first instance of a specified value within an array? Similar to:
Code:
var my_string = "string";
var index = my_string.indexOf("g");
/*Outputs:
1
*/
Basically, I have two arrays, each with 10 values (in slots 0-9 of the arrays). So I need to see if an array has a specified value in it, but then I have to see if the other array has a certain value in it, in the same spot as the first instance of what I search for in the first array.
View 4 Replies
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
Aug 1, 2006
I am writing a maze program for school. I am using a 2d array to represent to location of walls for the maze. The background (for figuring out where a player can move) is not the problem.I am using this algorithm for places the images...
for (i = 0; i < 22; i++) {for (j = 0; j < 16; j++) {if (maze[i][j] == 1) {instanceName = "wall" add i add j; //for multiple names for each instance
duplicateMovieClip("wall", newname = "instanceName", 1);
setProperty("instanceName", _x, (25*i+13));
[code]....
What needs to be done to use many copies of one instance to build the visible part of my maze? I want to be able to have all pieces anmed "wall" instead of "wall1", "wall2", etc...which isn't working anyway.
View 5 Replies
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
Nov 30, 2009
I have one swf with a button which, when clicked, needs to go to another swf in a different php page but to a specific frame, not the start of the movie.In the first swf I have:
register_btn.onRelease = function() {
getURL("http://www.myurl.co.uk?f=register");
}
[code].....
View 1 Replies
Oct 27, 2007
for example i have 2 swf file a.swf and b.swf can a.swf sending variable to b.swf? can a.swf control some movieclip in b.swf? in a case a.swf is loadMovie to b.swf...
View 4 Replies
Oct 21, 2009
My code:
Code:
onClipEvent (construct)
{
[code]....
View 6 Replies
Jul 5, 2011
there are 2 items on stage, one is the "button" with instance name myButton and a dynamic text field.so the action script goes this way...
myVar=0;
myButton.onRelease=function(){
myVar++;
trace("click");
}
the dynamic text is initially zero (0) and when i click the button it counts the clicks up to here every thing works right but...when .swf file previewed in html after clicks if refresh is pressed the number is going back to zero.i want to upload this file and use on webpage.
View 5 Replies
May 10, 2008
how I can declare a variable that is retrievable when the browser reloads.
View 7 Replies
Mar 18, 2009
I'm trying to create a unique variable and reference to it with myRewind for some button functions.
I'm trying to create this rewind+variable as the unique identifier but it just seems to be using myRewind as the variable and overwriting it.
Code:
//Setup subsection rollovers
function createRollover(myContainer, rollName) {
btnName = rollName+"_btn";
mcName = rollName+"_mc";
[Code]....
View 2 Replies
Apr 21, 2009
i have a movieclip called allBUTTONS which contains 18 buttons. This movieclip will be called numerous time on the CDROM I am creating, and each time the number of buttons visible will change. So instead of writing the following code numerous times for however many buttons i want visible:
[Code]..
View 3 Replies
Dec 29, 2009
Is there a way to recall a variable from a previous frame? I have a variable that was mathematically calculated in frame 3, that variable was then used in a dynamic text field. The problem I am facing is that the text field then disappears in frame 4. The only solution I can think of is reposting the text field in frame 4 but I am having trouble recalling the variable from the previous frame.
View 4 Replies
Jan 24, 2010
Basically, I wanted to 'save' the time thats been recorded in each of the 5 'games', so at the end there is a 'scores' page, with your times for each of the games.
I have managed to get the timer working for the games itself, but cannot find / work a method which saves them to the last frame?
I thought possibly converting the 'elapsed_time' into a different var (t1,t2 etc..) for each of the games? - doesn't seem to work timer_not_saving.fla
View 1 Replies
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
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
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
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
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
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
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
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
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
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
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