Actionscript 3 :: Convert Instance Variable To String?
Feb 2, 2011Is there a simple way to convert an instance variable to a String?
View 2 RepliesIs there a simple way to convert an instance variable to a String?
View 2 RepliesI'm slowly climbing the AS3 learning curve, I had a query about converting data stored in an Array:
My flash file contains six movieClips arranged into a grid, each movieClip is named with an instance name, increasing sequentially like so:grid1, grid2, grid3 ... etc
What I'm trying to achieve is to have one of the grid items randomly selected to play a contained animation every 2 seconds.[code]...
i have several button that should navigate to frames in my movie. the button have the same name as the frame's labels i need to convert the buttons' instance names to strings
stop();
import flash.events.MouseEvent;
this.Label1.addEventListener(MouseEvent.MOUSE_DOWN ,gotoLabel);
function gotoLabel(event:MouseEvent):void{
gotoAndStop('label1AsString');
}
I have a Flash poetry project in which I have 49 separate dynamic text boxes on stage. Each has a separate instance name - "cell_1", "cell_2", "cell_3" etc. I use the following code to store instance names in an array -
var j:int;
for (j = 1; j < 50; j++) {
instances.push("cell_"+j)
[code].....
I'm trying to turn an string into an instance name.
stage.focus = ["box_"+[i+1]];
this gives me back = box_2;
but I need it to be an object not a string.
In as2 I could use eval. How do I do it in as3?
so here's my problem. I've got an array (wall_inst[]) containing instance names of 3 objects (for now), however they are stored as text strings. I've got a moving 'ball' object too. The problem is, the values contained in the array are text strings and will not behave as instance names, when I try to get object properties off them etc. Eg, I can do this:
[Code]...
how can I convert String to Array(Instance Name)?The code below works fine.
Code:
var gridArray:Array = new Array(sq1_btn,sq2_btn);
gridArray[0].visible=false;
[code].....
I have multiple buttons, I would like, when the user presses a button, the name of that button is displayed as text on another frame.[code]
View 14 Replieshow is going your august? mine, as you're going to see...not ok at all! :P well, the point is:
[Code]...
Is it possible to convert a given variable name to a string?
ActionScript Code:
function vartostring(mystring:String) {
//something like var newstring:String = parsevarname(mystring)
trace (newstring);//output 'hello'
}
vartostring(hello);
Can I convert a string to a variable?For example:
Code:
var left = -100;
toVar( "left" );
function toVar(side)
{
trace(side); // I want to trace out -100 instead of "left"
}
Naturally I can remove the quotes in my function call so it would represent the variable instead of a string, but can I convert the string to the variable within the function?
I have been searching and searching but I have yet to come up with something that works.
Im new to Actionscript so I suspect this is somthing basic that I am missing[code]...
This my starting-point
1 I have to use a swf like: whatever.swf?file=abc1234
2 file=abc1234 represents the name of the xml file i need to load like[code]...
I made a sound file:
menuSound120 = new Sound(new URLRequest(http://audio.ngfiles.com/155000/155242_House_Rhythm.mp3))
I want to convert the name of this sound file to a string that reads "menuSound120." When I tried menuSound120.toString() I just got [object Sound].
Basically i have a variable that is a string and i need it to be a movieclip so that i can put it in an AS Tween.[code]...
View 7 Replieshow do convert the myString var which is a string to the class name?
var myString:String = "movieClipInTheLibraryClassName"
var t:myString = myString()
I'm using a library that has a function that returns an instance of some class Engine.
I'd like to tack on some interfaces to Engine, so I subclass it class InterfacedEngine extends Engine implements AwesomeInterface. but when I change the code that uses the classes from this:
var engine:Engine = generateEngine();
to this: var interfacedEngine:InterfacedEngine = generateEngine();
It gives me a runtime error (elision mine):
TypeError: Error #1034: Type Coercion failed: cannot convert ...::Engine@1bc2bf11 to ....InterfacedEngine.
What about AS3 classes am I misunderstanding?
f you know PHP...then you know that you can create a string variable...and then use the value of that variable to declare another variable. like this:
PHP Code:
<?php$foo = "haha";$i{$foo} = "success";print $i{haha};?>
and it would display "success"...or like this:
PHP Code:
<?php$foo = "haha";$$foo = "success";print $haha;?>
and it would also display "success".
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 )();
}
I have a String variable in my flex (flash builder 4) application containing CSV data. I need to allow the user to download this data to a local file. For example, giving them a "csv" button to click and it might present them with a save file dialog (and I would be sending the contents of my string variable).Is this possible / how ?I am using the ResuableFX component for the datagrid to csv. This the code I ended up with that works to save the string to a text file for the user (in a web browser):
var dg2CSV:DataGrid2CSV = new DataGrid2CSV();
dg2CSV.includeHeader=true;
dg2CSV.target=adgEncounters;
[code]......
If i have an ASP page that is returning variables (and I can see them in the debugger) how do i consentrate a string to call that variable?
ie:
variables being returned are named:
"res1", "res2", "res3"...etc
for (var i = 0; i < 10; i++) {
[Code]...
Trying to replace a portion of a string with a "-" if it matches a string variable in AS3.
var re:RegExp = new RegExp(imageArray[j][1],"gi"); trace(imageArray[jTemp][2].replace(re,"-"));
imageArray[jTemp][2] is a string imageArray[j][1] is a string as well I'm not getting the result I expect. I would like trace above to return 'permanentContainer-' Here are the traces for the above variables
permanentContainer-temporaryContainer- temporaryContainer
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.
I have 40 movieclips, with the instance names p[1-40] (for example, p14 or p32). I want them all to do something in order, so I'm using a 'for' loop. In simplified psuedo-code, it looks like:
for 40 {
variable = variable + 1
p[variable]
[code].....
I want to take the following information, which I have as a string in Flash, and convert it into an XML object in AS3:
// information
<list>
<a>
[code].....
how you would target a function's local variable through a concatenated variable string.For example:
var txt = "Hello World";
function testing(msg) {
var test1 = msg;[code].........
I'd expect the trace to be "Hello World" but rather is given "undefined". So if variables created outside functions are created on the main timeline, where are local function variables created and how would you access them?
var txtI:TextField=new TextField();
txtI.text="Germany";
txtI.gotoAndPlay(2); // so this should mean Germany.gotoAndPlay(2)
I'm trying to convert an variable that contains XML data to a String. Anyone have a clue on how to achieve this?
My main problem is that the XML data is formatted nicely, but I need to store it in the database without the linebreaks and tab stops and whitespaces.
I think converting it into string would work with .toString();, but that doesn't get rid of the XML formatting...
Code:
function f_choosePhoto(photoNum)
{
var photos:Array = ["photo0","photo1","photo2"];
[Code].....
I've cobbled the AS together from a couple of seperate tutorials, and if I replace "new this[path](560, 380);" with "new photo1(560, 380);" it works.
I want to simply some repetitive code like this:
letter1.gotoAndPlay(Math.round(Math.random()*letter1.totalFrames));letter2.gotoAndPlay(Math.round(Math.random()*letter2.totalFrames));letter3.gotoAndPlay(Math.round(Math.random()*letter3.totalFrames));
I want to store letter1... into a string array. so I can call all of them with a loop.