Convert A String To Code (dynamically)
Hello everyone,
This is the first time I write on this forum, I'm not a very experienced actionscript coder so please please please give me some help. my problem is:
I would like to dinamically store, call, etc. etc. _root.myclip_1._currentframe _root.myclip_2._currentframe _root.myclip_3._currentframe ...and so on...
//============================================= onEnterFrame = function () { // code code code code var currentArray:Array = new Array(); for (i=0; i<N; i++) { currentArray[i] = ('_root.mc_disegna_'+i+'._currentframe'); } var totalArray:Array = new Array(); for (i=0; i<N; i++) { totalArray[i] = ('_root.mc_disegna_'+i+'._totalframe'); } //=============================================
Now, if I do
trace(currentArray[6]); trace(totalArray[6]);
I get _root.myClip_6._currentframe and _root.myClip_6._totalframe
and I would like to get 1 (which is the _currentframe value of myClip) and 24 (which is the _totalframe value of myClip). the thing is that, even after the cycle, the sucker reads '_root.mc_disegna_'+i+'._currentframe' as a string whether I would like to make flash read it as a piece of code.
once the problem will be solved I'll be able to do something like
if (currentArray[i] == totalArray[i]) { trace('I've seen the light !!!') }
cringin' 4 help, JoKerDev
ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 01-11-2007, 02:23 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Convert String Into Actionscript Code
I need one function that converts string into actionscript code,
i've been searching but I don't find anything. I'm using Flash 8.
Example:
myString = "Number(var1.txt) * Number(var2.txt) + 1000";
result.text = desiredFunction(myString); // is equal > result.text = Number(var1.txt) * Number(var2.txt) + 1000;
Thanks
Convert String Into Actionscript Code II
Please.. help me with this.
The function above arithmeticParser() by abeall works great BUT,
it doesn't read variables, if I have a variable name "var1" or an instance name "var1.text"
How can I assign to the array the value instead of the variable string?
actionscript layer1:
<code>
/************
/* String arithmetic parsing function - abeall.com
/* takes a string like "1+(5-2)/7((25+3)*2)" and does the arithmetic, respecting parenthesis
/* returns: Number
/************/
function arithmeticParser(str){
if(typeof str!='string')return str;
//clean up
str = str.split(" ").join('').split("Number").join('');
//CORE ALGORITHM///////////////////////////////////
//create nested arithmetic array based on parenthesis
//ex: 1+(5-2)/7((25+3)*2) => ['1','+',['5','-','2'],'/','7',[['25','+','3'],'*','2']]
var arithArr = [];
var currStr = "";
var arrayScope = [arithArr];
for(var i=0 ; i<str.length ; i++){
var char = str.charAt(i);
var currArr = arrayScope[arrayScope.length-1];
if(char=="("){
if(currStr!="")combineArray(currArr,currArr.length ,arithStrToArray(currStr.split("(").join()));
currStr = "";
arrayScope.push(currArr[currArr.length]=new Array());
}else if(char==")"){
combineArray(currArr,currArr.length,arithStrToArra y(currStr.split(")").join()));
currStr = "";
arrayScope.pop();
}else{
currStr = currStr + char;
}
}
combineArray(currArr,currArr.length,arithStrToArra y(currStr));
//dump(arithArr);
str = arrayArithmetic(arithArr);
return str;
//FUNCTIONS////////////////////////////////////////
//splices all elements in the Array 'insertArr' into the Array 'ar' at 'index'
function combineArray(ar,index,insertArr){
for(var i in insertArr){
ar.splice(index,0,insertArr[i]);
}
}
//performs arithmetic() to 3D arrays from deepest array to the top array
function arrayArithmetic(ar){
for(var i in ar){
if(typeof ar[i]=='object'){
ar[i] = arrayArithmetic(ar[i]);
}
}
return arithmetic(ar);
}
//converts arithmetic string to array
//ex: 7+2/8-12 => ['7','+','2','/','8','-','12']
function arithStrToArray(arithStr){
var ar = [];
var currStr = "";
for(var i=0 ; i<arithStr.length ; i++){
var char = arithStr.charAt(i);
if(char=="/" || char=="*" || char=="-" || char=="+"){
if(currStr!="")ar.push(currStr);
ar.push(char);
currStr = "";
}else{
currStr = currStr+String(char);
}
}
if(currStr!="")ar.push(currStr);
return ar;
}
//performs the four basic arithmetic operations to arithmetic formatted array
function arithmetic(ar){
for(var i=0 ; i<ar.length ; i++){
if(ar[i]=="/"){
var n = Number(ar[i-1]) / Number(ar[i+1]); //perform operation
ar.splice(i-1,3,n); //splice out the number,operation,number subarray and replace with the answer number
i=0; //since the array has been modified(spliced) the operation must start over to get all operations
}
}
for(var i=0 ; i<ar.length ; i++){
if(ar[i]=="*"){
var n = Number(ar[i-1]) * Number(ar[i+1]);
ar.splice(i-1,3,n);
i=0;
}
}
for(var i=0 ; i<ar.length ; i++){
if(ar[i]=="-"){
var n = Number(ar[i-1]) - Number(ar[i+1]);
ar.splice(i-1,3,n);
i=0;
}
}
for(var i=0 ; i<ar.length ; i++){
if(ar[i]=="+"){
var n = Number(ar[i-1]) + Number(ar[i+1]);
ar.splice(i-1,3,n);
i=0;
}
}
return ar[0]; //the array should be down to one element: the answer
}
}
</code>
actionscript layer2:
<code>
myString = "(var1 * 2) + 1000";
result.text= arithmeticParser(myString);
</code>
Convert String Into Actionscript Code
I need one function that converts string into actionscript code,
i've been searching but I don't find anything.
Example:
myString = "Number(var1.txt) * Number(var2.txt) + 1000";
result.text = desiredFunction(myString); // is equal > result.text = Number(var1.txt) * Number(var2.txt) + 1000;
Thanks
Convert String Into Actionscript Code II
Please.. help me with this.
The function above arithmeticParser() by abeall works great BUT,
it doesn't read variables, if I have a variable name "var1" or an instance name "var1.text"
How can I assign to the array the value instead of the variable string?
actionscript layer1:
<code>
/************
/* String arithmetic parsing function - abeall.com
/* takes a string like "1+(5-2)/7((25+3)*2)" and does the arithmetic, respecting parenthesis
/* returns: Number
/************/
function arithmeticParser(str){
if(typeof str!='string')return str;
//clean up
str = str.split(" ").join('').split("Number").join('');
//CORE ALGORITHM///////////////////////////////////
//create nested arithmetic array based on parenthesis
//ex: 1+(5-2)/7((25+3)*2) => ['1','+',['5','-','2'],'/','7',[['25','+','3'],'*','2']]
var arithArr = [];
var currStr = "";
var arrayScope = [arithArr];
for(var i=0 ; i<str.length ; i++){
var char = str.charAt(i);
var currArr = arrayScope[arrayScope.length-1];
if(char=="("){
if(currStr!="")combineArray(currArr,currArr.length ,arithStrToArray(currStr.split("(").join()));
currStr = "";
arrayScope.push(currArr[currArr.length]=new Array());
}else if(char==")"){
combineArray(currArr,currArr.length,arithStrToArra y(currStr.split(")").join()));
currStr = "";
arrayScope.pop();
}else{
currStr = currStr + char;
}
}
combineArray(currArr,currArr.length,arithStrToArra y(currStr));
//dump(arithArr);
str = arrayArithmetic(arithArr);
return str;
//FUNCTIONS////////////////////////////////////////
//splices all elements in the Array 'insertArr' into the Array 'ar' at 'index'
function combineArray(ar,index,insertArr){
for(var i in insertArr){
ar.splice(index,0,insertArr[i]);
}
}
//performs arithmetic() to 3D arrays from deepest array to the top array
function arrayArithmetic(ar){
for(var i in ar){
if(typeof ar[i]=='object'){
ar[i] = arrayArithmetic(ar[i]);
}
}
return arithmetic(ar);
}
//converts arithmetic string to array
//ex: 7+2/8-12 => ['7','+','2','/','8','-','12']
function arithStrToArray(arithStr){
var ar = [];
var currStr = "";
for(var i=0 ; i<arithStr.length ; i++){
var char = arithStr.charAt(i);
if(char=="/" || char=="*" || char=="-" || char=="+"){
if(currStr!="")ar.push(currStr);
ar.push(char);
currStr = "";
}else{
currStr = currStr+String(char);
}
}
if(currStr!="")ar.push(currStr);
return ar;
}
//performs the four basic arithmetic operations to arithmetic formatted array
function arithmetic(ar){
for(var i=0 ; i<ar.length ; i++){
if(ar[i]=="/"){
var n = Number(ar[i-1]) / Number(ar[i+1]); //perform operation
ar.splice(i-1,3,n); //splice out the number,operation,number subarray and replace with the answer number
i=0; //since the array has been modified(spliced) the operation must start over to get all operations
}
}
for(var i=0 ; i<ar.length ; i++){
if(ar[i]=="*"){
var n = Number(ar[i-1]) * Number(ar[i+1]);
ar.splice(i-1,3,n);
i=0;
}
}
for(var i=0 ; i<ar.length ; i++){
if(ar[i]=="-"){
var n = Number(ar[i-1]) - Number(ar[i+1]);
ar.splice(i-1,3,n);
i=0;
}
}
for(var i=0 ; i<ar.length ; i++){
if(ar[i]=="+"){
var n = Number(ar[i-1]) + Number(ar[i+1]);
ar.splice(i-1,3,n);
i=0;
}
}
return ar[0]; //the array should be down to one element: the answer
}
}
</code>
actionscript layer2: (usage)
<code>
myString = "(var1 * 2) + 1000";
result.text= arithmeticParser(myString);
</code>
Convert Multiline String To A One Line String With RegExp
better get my own thread for that
How can I convert a multiline String to a one line String?
EX:
PHP Code:
Testing is always full of man made bugs.
<a href="http://www.betterthannothing.com" title="betterthannothing" target="_blank">
<font color="#22229C">Believe</font>
</a>
me when times comes that you have to
<a href="http://www.vreate.com" target="_blank">create</a>
useless stuff to test some other useless stuff to have
<a href="http://www.vreate.com">some</a>
real results.. its a pain.
<img src="http://www.markval.com/deerPack.jpg" height="484" width="352"/>
<em>Got to try that stuff to eventually love it one day.</em>
and should result in
Code:
Testing is always full of man made bugs.<a href="http://www.betterthannothing.com" title="betterthannothing" target="_blank"> <font color="#22229C">Believe</font></a>me when times comes that you have to<a href="http://www.vreate.com" target="_blank">create</a>useless stuff to test some other useless stuff to have<a href="http://www.vreate.com">some</a>real results.. its a pain.<img src="http://www.markval.com/deerPack.jpg" height="484" width="352"/><em>Got to try that stuff to eventually love it one day.</em>
I think it have to play with the ^ (caret) and m (multiline) ... just need to put the puzzle together.
Convert Html String To Xhtml String
Anyone know of a great way to convert an html string format from flash into a resembalnce of xhtml for outputing to a server or a direction i could go in to do this.
Thanks
Convert Html String To Xhtml String
Anyone know of a great way to convert an html string format from flash into a resembalnce of xhtml for outputing to a server or a direction i could go in to do this.
Thanks
Save Object To String -> Load String And Convert Back To Object?
Wondering if anyone knows if this is possible. First a little explanation:
1. I have container grid where you can add and position MC's
2. The MC's x,y and other data is stored in a 3d object
3. The object is setup like this: matrix (object) -> levels (objects) -> profiles (objects). So basically a grid which mirrors what you see on screen.
This all works great; however, the application needs to have a save feature. My first thought was decode the matrix into an XML and save that.
Then I thought maybe you can just convert the matrix object to one big string and save that.
Questions: when the string is loaded back into the movie how do you (or can you even) covert it back in a object that flash can read?
Any help/input is greatly appreciated.
Convert To String?
I load variables from a text file named :
&first1=John
&first2=Mark
&first3=Tim
&first4=Mike
I am evaluating them in a loop by constructing the variable I want to test and assigning it the value of first1, first2, etc. based on the current loop iteration
For Example, during iteration start_num=1 :
test_first = "first";
test_first = test_first.concat(start_num);
run_first = eval (test_first);
This makes the variable I want to test, run_test, and assigns it the value of, first1, which is John. So :
run_test=John
However, I am comparing, run_test, to a input from a text box, text_input. text_input is type string, but run_test is type undefined.
How do I convert the variable run_test to a string so I can evaluate it in an IF statement?
Convert To String
I load variables from a text file named :
&first1=John
&first2=Mark
&first3=Tim
&first4=Mike
I am evaluating them in a loop by constructing the variable I want to test and assigning it the value of first1, first2, etc. based on the current loop iteration
For Example, during iteration start_num=1 :
test_first = "first";
test_first = test_first.concat(start_num);
run_first = eval (test_first);
This makes the variable I want to test, run_test, and assigns it the value of, first1, which is John. So :
run_test=John
However, I am comparing, run_test, to a input from a text box, text_input. text_input is type string, but run_test is type undefined.
How do I convert the variable run_test to a string so I can evaluate it in an IF statement?
How To Convert 'this' To A String
I want to take the keyword this and convert it to a string to use later in my function does anyone know how to do it?
if I trace(this) - I get the string that I want to use but it doesn't seem to be a string.
this.toString(); traces as [object Object]
I may be getting close but I though this might be easy for someone with more experience.
thanks!
Convert The Value Of This To A String?
I need to be able to get sub strings of This.. but when I try, it says undefined...
If you trace(this) you get like _level0.container1
I need to substring it so i can read the last character.. the 1... but it won't let me
how can i do this?
How Can I Convert A Value Into A String?
this code is inside a instance called clip1:
someval = this._name;
trace(someval);
how can I get the output to be: "clip1"? because now the output is just: clip
And I really need to get thous darn "" there.
big thanks im really stuck here.
yours in faith Neptunesnectar.
How To Convert XML Value To String
distdata.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue
The above line returns me a value, i want to convert this in to string value.
how can i do this ?
Convert String To Int
Been searching for a simple way to do this but it's not out there, or is it?
I simply need to convert a sting to an int. The string will be a number, that is a given.
Convert This To String
Hi everybody,
I duplicate lot of mc
ActionScript Code:
for (var i:Number; i < n; i++)
{
empty.mc0.duplicateMovieClip("mc"+i, this.getNextHightsDepth());
empty["mc"+i].onRelease = function()
{
//now i wont when i release that start script which depends on i
//my idea is that i use trace(this)
//_level0.empty.mc0
//_level0.empty.mc1
//_level0.empty.mc2
//.....
//when i add
test_txt.text = this;
//i can see path
//but i dont know how to convert him to string
//because I wont to separate only number at the end with .substr(-1,1)
}}
this is my idea can anyboy help me???
thanks in advance
Convert String To Hex
I'm trying to convert a string value to a hex value so the user can specify a custom color that will be used to draw a line. Is there any way I can do this?
I don't want to have buttons that supply preset colors. I want it to be completely customizable.
Thanks
Convert Int IP To String
Hello, i'm trying to make a IRC client, but when the server send me the PING command, i can't respond because i think it s IP is coded in integer and i think i need to convert it so i could open a connection and sent it the PONG command back without being kicked, thanks.
Convert Asp String To UTF-8?
Hello,
I have a plain text file with special charset like ' ëèé'
I finally got it to work. But now i am trying to use a asp file to write out the text. But i don't
know how to convert to UTF-8 in ASP.
I have this, but it still does not work:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>TEST</title>
</head>
<%
'set output character set
Response.CharSet = "utf-8"
Response.Write("This is a test éèè")
%>
</body>
</html>
Does anyone has knowledge of how this could be done?
Regards,
Micheal.
How To Convert A String Into A Value ?
guys , is there any way to convert a string into a value ?! like the user will enter something like this in a textbox (5 + 7^5 * 3) and i wanna calculate the value. it there anyway to do this other than studying the expression char by char and analyse the operations ?!!!
Newbie Convert Button Code To Frame Code
Hi all!
I guess this is a really simple one.
I have a button with the following code attached to it:
PHP Code:
this.onRelease = function() { SWFAddress.setValue('/portfolio/');}this.onRollOver = function() { SWFAddress.setStatus('/portfolio/');}this.onRollOut = function() { SWFAddress.resetStatus();}
I want to use this code on a frame. Is it onLoad I need to use??
Convert String To Array
Hi!!!!
i have a big trouble, I read a variable from mysql database, just like this:
posH=123,432,34,345....
But whe I read the variable in flash it comes in form of string and not like array.
I try with the funtion eval(); but dont work fine =[
Jus I like convert this:
x = "1,2,3"
// to
x = [1,2,3]
thx .... =]
How To Convert String To Funtion?
hi all.
does anybody know how to convert a string to a function?
say i import the string "myfunction()". is there any way to make flash execute myfunction()? nothing i have tried works. please let me know!
thanks,
larry armstrong
I Need To Convert A String To A Number
Hello all,
I have a value stored in a variable called "numba"
I get the value like this:
numba=this._name.substring(6,this._name.length);
the value is a string, when I trace(numba) I get something like this:
0
1
2
3
4
I want to add a value of 1 to the variable called numba.
The problem is that the value of the variable numba IS A STRING. so when I try to add 1 to it like this:
newNumba=numba+1;
the trace looks like this:
01
11
12
13
14
I want it to simple return 1,2,3,4,5
how can I convert my string(numba) into a real number?
I have tried turning the string into an object but it didnt work out.
Much thanks to any takers,
~Apolo
Convert String To Expression
im trying to diplay the contents of the different variables (named proj...1,2,3,4,5,6" in a dynamic text box. Although i can get the target correct concaternating the string "_root.proj" with variable _root.b the dynamic text box (t) will not read the resultant code as an expression and therfore diplays _root.proj1.
the expression box is checked on the value of variable this.t
anybody help please. The answer is probably simple
here's the code
james
onClipEvent (load) {
x = "_root.proj" + _root.b;
this.t = x;
}
Convert String To Number
Hello if anyone can help with this probably simple issue....
I load some variables from a database or textfile and some of those are numbers. Now I tried to convert them using parseInt() and that works fine, however if I try to convert an integer value, for example 1.33 it goes wrong!
Any suggestions?
Convert String To Referenc3
hi
i have a string that i want to convert to reference the object, if u know wat i mean.
///////////////// this is my string ////////////
trackTopNum = 5;
return Object("_root.game_mc.track" + trackTopNum);
////////////////////////////////////
but i want to perform hitTest with it.
///////////////// this doesn't work////////////
_root.game_mc.track5.hitTest(something);
/////////////////////////////////////////////////
is there a way?
thanks.
How Do I Convert A String To An Array?
myArray = "[ [1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,1],
[1,0,1,0,0,0,0,1],
[1,0,0,0,0,1,0,1],
[1,0,0,0,0,0,0,1],
[1,1,1,1,1,1,1,1] ];
Convert String To Array
is there some way to convert a string to an array?
let's say I have a variable which contains a string:
mystring = "[20,546,60]"
and I want actionscript to pass this data to an array, and the result would be for example this.
mylist = [20,546,60]
like:
mylist[1] = 20
mylist[2] = 546
mylist[3] = 60
thanks
How To Convert String To Number?
I have an external text file and it's content is simply "quantity=3".
Then I loadVariablesNum to load this external text file into flash.
As expected the variable called quantity will be a string of "3".
I want to change this string to a number.
So I put in this statement "var newquantity = Number(quantity)".
Unfortunately this doesn't convert the variable quatity from a string to a number?!!
I know that the above statement will work if the variable "quantity" is defined internally, instead of loaded externally.
My question is how should I load a number into flash ... instead of loading a string. Thanks
How To Convert String To Number?
all Mc's are named object1, object2 ect. From there I split the the name to get the number at the end of the Mc's name. From there I will be running a function that controlls all the MC's with numbers above the selected MC.
ie click on object2 there fore object3, object4 and object 5 will animate.
The problem is with activating only those above the selected target. I thought I could use ObjectNumber (in this case 2) and add one to that varaible - hoping that it becomes "3" but instead I get "21"
var objectNumber:Number = this._name.slice (6);
var objectNext:Number = objectNumber+1;
trace ("Next object number is "+objectNext)
OUTPUT is :" 21" (2&1 not 2+1??)
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
How To Convert Droptarget Value To String?
low guyz...
i would like to know how to convert the return value of the droptarget into string.. so that i can split it..
this is the code that i made but it didnt work:
ActionScript Code:
on (press) {
startDrag(this, true);
}
on (release) {
stopDrag();
dropTar = eval(this._droptarget);
var target_Array:Array = dropTar.split("_");
for (var i = 1; i<target_Array.length; i++) {
trace("splitted ["+i+"]:"+target_Array[i]);
}
}
i need ur help guyz.. thankz!
Convert String To Number
i have a string and want it to covert to a number...how ?
for the live of me why does this not work !
temp_name = "Folder_name" + (number + c) ; //number is 1 , c = 0
trace("tempname = " + temp_name ); //gives me Folder_name10
i want it to ADD and make it 1 eg. Folder_name1
Convert String To Number
hey,
I am trying to convert a number in an external text file from a string into number... sounds simple but it just doesnt work...
Code:
var externalData:LoadVars = new LoadVars();
externalData.onLoad = function() {
color_txt.text = externalData.colorCode;
}
externalData.load("colorCode.txt");
var myNumber:Number = Number(color_txt.text);
trace (myNumber);
when I trace the "myNumber" it outputs 'NaN'
Convert A String To A Number
Hello,
I have a problem which is annoying me, is there anyway of converting a string to a number!? I know its not a normal thing to do but i need to!!
Can anyone please help that would be great.
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;
Convert String To Number
Hi, ppl
I'm a newby in flash 8, and I have a big problem:
Why this script dont work in flash 8, and work in flash 7 ??
on (release) {
var results:Number = Number(ca)/(Number(cb)*Number(cb))*10000;
result = Math.ceil(result);
}
Please anyone can help me to make this work in flash 8
Thanks
Convert String To A Number
Hi everybody.. I need some help with Flash8,
My intention is to read a number from a txt file, I did it with that code:
-> loadVariables("amount.txt", totalAmount), //amount=100 in the txt file
and then I transfer the txt file content to a variable "outputAmount" :
-> outputAmount = totalAmount;
if I trace(outputAmount); I can see the amount 100
... is working but the problem is, flash consider "ouputAmount" as a string not as a number even if I put this code :
-> outputAmount = Number(totalAmount); (working on flashMX not on flash 8)
Then I can't make any '+ * / -' so HOW can I convert my outputAmount content to a number... to have the opportunity to make an '+ - * /'
Your help wil be APPRECIATE
Thank you
Jzeel
Convert HEX To String Literally
Simple question I guess,
How can I convert hexadecimal values like 0xff0000
to a string with the same symbols like this:
"ff0000"
Convert String To Type
Hi,
How do you convert a String to a Type?
Like being able to create a "Some String" object?
var something:"Some String" = new "Some String";
How To Convert A String To An Object?
Hi all,
I have a problem I ws hoping someone could help me with. I am trying to build a generic function that takes in an event object from a mouseover event, renames the target name (ex. old target=h1 , new target name=b1) with regexp then calls that new object instance to play a frame (b1.gotoAndPlay(2)). This is so I can have h1, h2, h3 event activate target play on b1, b2, b3 with regexp.
Code below:
// events
h1.addEventListener(MouseEvent.ROLL_OVER, over);
h2.addEventListener(MouseEvent.ROLL_OVER, over);
function over(evt:MouseEvent):void
{
var newTarget:String;
var oldTarget:String = evt.target.name;
newTarget = oldTarget.replace('h','b');
//??? this doesn't work because its not an object but string currently
newTarget.gotoAndPlay(2);
}
Any thoughts? I could always do a if loop (if h1 then b1.gotoAndplay, if h2 then b2.gotoAndPlay etc.. but seems like bad practice... )
PLease let me know if you need more information, this is my first time posting to a technical forum
Thanks in advance.
Convert String To Variable
Probably a real simple problem, but it is driving me nuts! I have a list of variables that serves as a script for a text-based game (line1, line2, etc.) I also have a number variable that grows by 1 with each line. But I can't figure out how to convert a string into a variable:
Code:
var line1:String = "This is the line.";
var currentLineNumber:Number = 1;
trace("line" + currentLineNumber);
This (as I'm sure you know) is returning "line1", instead of what I want, which is "This is the line."
Any suggestions? Thanks!
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.
Convert String To A Number
I am trying to compare two items for equivalency - one is a string in a text box, and the other is a number held in a variable. I can't seem to get an if statement like
ActionScript Code:
if (_root["guess"] == totalCash){
do something
}
to work. Do I have to convert the string to a number to do this? I keep getting negative results eventhough the string and the number match. If I have to convert to a number, how would I do that (ie "123" converted to 123)?
I tried Number() but that didn't seem to work. I searched the forums without success. Please help.
|