Casting A String Into A Function
Hi, I would like to convert a String to a function: Code: public function Init(command:String){ //i need to call the handleHowTo() function from here base on the command String}public function handleHowTo(){ trace("yes");} Init("handleHowTo");How can I convert the command:String to a function to call the function handleHowTo() ? is there a way to cast a String into a Function ??? Thanks ;)
ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 10-18-2007, 03:21 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Casting A String To An Object
I'm having trouble passing an object parameter using a string concatenation in a for loop...
in the for loop, I duplicate movieClips, copying a movie called "glass" and try to register it's speeds with the register() function below.
for (i = 1; i <= numObjects; i++) {
duplicateMovieClip(glass,"glass" + i, i);
register("glass" + i,20,20,20);
}
function register(object, xspeed, yspeed, rspeed) {
objects.push(object);
object._xspeed = xspeed * (2 * Math.random() - 1);
object._yspeed = yspeed * (2 * Math.random() - 1);
object._rspeed = rspeed * (2 * Math.random() - 1);
}
unfortunately, when passing tmp as "glass" + i, register thinks its a string, not an object. The object appear on stage, but doesn't move. If I hard code register() passing in as register(glass2,20,20,20) it does move.
How do I cast the string I pass in as an object?
Help Casting A String To A Number
I've got a String value I'm trying to pass into a beginFill() function, but it's not happy with a String and gives me this error: "1067: Implicit coercion of a value of type String to an unrelated type uint. I've tried casting using "hexString as Number" but that turns my pretty "0xFFFFFF" into something like 106425. Any suggestions on how to give beginFill a value that's originally a String?
ActionScript Code:
private function createBG(hexString:String):void
{
// this doesn't work - it turns my "0xFFFFFF" format into a numeral
//var bgColor:Number = hexString as Number;
var bg:Shape = new Shape();
// pre-defined colored bg, starting at point 0, 0
bg.graphics.beginFill(bgColor);
bg.graphics.moveTo(0, 0);
bg.graphics.lineTo(stage.width, 0);
bg.graphics.lineTo(stage.width, stage.height);
bg.graphics.lineTo(0, stage.height);
bg.graphics.lineTo(0, 0);
addChild(bg);
}
Casting String To Uint
Hello,
Does anyone know how to cast a string into a uint?
I have tried some along the lines of the following:
var myStr:String = "0x000000";
var myUint:uint;
myUint = uint(myStr);
But i keep getting an error stating that there is a mismatch in variable types or i get a value of '65280' when I trace myUint. I understand that uint is a positive integer but i need to accept a string for the colour value and need to convert it to a string for use.
Any suggestions and correct answers are welcome. I will post or indicate the working solution once this problem has been solved.
Thanks in advance to everyone,
Lee
Edited: 11/26/2008 at 03:42:18 AM by leej_w
Help: Casting String Gotten From Xml To A Number Type
Hi all,
I have a major problem, I have parsed the data from an xml doc to global vars in flash and need to use a few of them as numbers for things the position of "nodes" on the screen. However I can not cast the data stored as a var to a number or int value.
For example in the code below when the set Node button is pressed it traces the "Node's" current X value, then the value in the global var gotten from the xml, which contains the x position of where to place the Node.
Next it creates a new var of Number Type and assigns it the Number value of the string in global var.
It then traces the new value of SNtopLeftX and sets the x pos of the Node's movie clip to the value of SNtopLeftX
However the Node doesn't move and this is the output I get from the traces
Start Node is at x = -734.5
nod_topLeftX is 16
TopLeftX = 16
SN TopLeftX = NaN
I do not understand why I am getting NaN when the string of nod_topLefX is 16, any ides?
-------------------------------------------------------------------------------------------------------------------
Attach Code
butNodeSet.onRelease = function() {
trace ("Start Node is at x = " + mcStartNode._x);
trace ("nod_topLeftX is " + nod_topLeftX);
var SNtopLeftX:Number = Number(nod_TopLeftX);
trace ("StartNode TopLeftX = " + SNtopLeftX);
mcStartNode._x = SNtopLeftX;
}
Help: Casting String Gotten From Xml To A Number Type
Hi all,
I have a major problem, I have parsed the data from an xml doc to global vars in flash and need to use a few of them as numbers for things the position of "nodes" on the screen. However I can not cast the data stored as a var to a number or int value.
For example in the code below when the set Node button is pressed it traces the "Node's" current X value, then the value in the global var gotten from the xml, which contains the x position of where to place the Node.
Next it creates a new var of Number Type and assigns it the Number value of the string in global var.
It then traces the new value of SNtopLeftX and sets the x pos of the Node's movie clip to the value of SNtopLeftX
However the Node doesn't move and this is the output I get from the traces
Start Node is at x = -734.5
nod_topLeftX is 16
TopLeftX = 16
SN TopLeftX = NaN
I do not understand why I am getting NaN when the string of nod_topLefX is 16, any ideas?
------------------------------------------------------------------------------------------------------------------- This is my Code
butNodeSet.onRelease = function() {
trace ("Start Node is at x = " + mcStartNode._x);
trace ("nod_topLeftX is " + nod_topLeftX);
var SNtopLeftX:Number = Number(nod_TopLeftX);
trace ("StartNode TopLeftX = " + SNtopLeftX);
mcStartNode._x = SNtopLeftX;
}
Flash MX Casting Problems: String Value To Object._name?
I am importing delimited from asp that I have split into an array.
I'm trying to tell a movie clip instances to play with the move clip name based off the [i] "numbers".
I can get setproperty to render the visibility property however I can seem to get the casting of the variable right in order to tell the movie to play.
Example of what I need to work.
Array [0] //Output: mc25 which is also the name of a mc instance.
newmc= Array[0];
newmc._play;
The above doesn't work and I know that is somehow related to newmc being a string value. How do I convert the sting back to a mc._name?
Also:
[-----Works---------------------------------------------------------]
chec=b25;
bog= chec;
group=bog;
setProperty(group,_currentframe,group.gotoAndPlay( group._currentframe+1));
displaytextbox=group;------------------------------------------------------------------------
[----Doesn’t-------------------------------------------------------]
chec=b25;
bog=String(chec);
group=bog;
setProperty(group,_currentframe,group.gotoAndPlay( group._currentframe+1));
displaytextbox=group; -----------------------------------------------------------------------
Any Ideas?
Problems With Casting Or String (literals?), And Dynamic References
Can someone please tell me the difference in these three code chunks?
1) is it casting a string, or incorrect syntax?
2) this works,
3) if #2 works as a plain "" string, then what cases would prompt the string to need String("whatever") ?
if menu_item_txt is a textField at _level0:
1)
Code:
for (var i = 0; i < 7; i++) {
var myText:Object = this[String(menu_item_txt) + i];
//trace(myText);
myText.autoSize = true;
myText.embedFonts = true;
myText.antiAliasType = "advanced";
myText.gridFitType = "subpixel";
myText.thickness = 0;
myText.sharpness = 45;
}
2)
Code:
for (var i = 0; i < 7; i++) {
var myText:Object = this["menu_item_txt" + i];
//trace(myText);
myText.autoSize = true;
myText.embedFonts = true;
myText.antiAliasType = "advanced";
myText.gridFitType = "subpixel";
myText.thickness = 0;
myText.sharpness = 45;
}
3)
Code:
for (var i = 0; i < 7; i++) {
var myText:Object = this[String("menu_item_txt") + i];
//trace(myText);
myText.autoSize = true;
myText.embedFonts = true;
myText.antiAliasType = "advanced";
myText.gridFitType = "subpixel";
myText.thickness = 0;
myText.sharpness = 45;
}
Return Function Name (Function => String)
I keep coming across problems where it would be really convenient to get the name of a function in string format - like arguments.callee only a string instead of [Function, Function].
I haven't thought of a way to do this but in my head the keywords 'prototype' and 'override function' keep coming up - albeit that seems like a horrible horrible idea, but Function does extend Object so...thoughts?
String With Function Name To Call Function?
hi guys,
it so happened that I have to call some function from XML. What is the best way to do this??
say i have a class "ABC.as" with a function "def()" can I do this:
Code:
var abc:ABC = new ABC();
var strg:String = "def()";
//then i call the function...
abc.strg;
is this going to work?? else is there any solution can let me do something similiar?
thanks!
String & Function
I juste like to know where i can learn about string and function
thx
Eric
String To Function ?
I´m trying to "dynamically" set the tween function in the arguments for a tween, made with mx.transitions.Tween.
function tweenBall(twFunc) {
var myTween:Tween = new Tween(ball, "_x", twFunc, 50, 450, 2, true);
}
The problem is that the parameter sent into the function (twFunc) is a string...
Of course it works if I set the tween-function inside this...
function tweenBall(twFunc) {
test = Bounce.easeIn;
var myTween:Tween = new Tween(ball, "_x", test, 50, 450, 2, true);
}
So....how do I "convert" the incoming string to a function?! Know about the "toString" command....and would like a "toFunction" command.... :-)
Thanx in advance...
Function From String
I'd like to construct a function from a string..
IE (in javascript):
var myFunc = eval("function() { alert('hello'); }");
Is there something similar in ActionScript?
I've tried:
eval("function() { trace('hello'); }");
var myFunc = new Function("trace('hello');");
myFunc();
Function(string)
Hi all.
I have been trying to convert a string into code/script in the last 3 days but no matter what I tried, I couldn't do it. Here's an example of the string
ActionScript Code:
var myString:String = 'trace("hello!")';
I found a forum discussing a similar issue but that one calls the function name (in here and in here). So I'm stuck.
Does anybody have an idea?
Thanks in advance.
String Function Help
I'm getting a value of D:// returned to me. I want to set a variable equal to just the letter D (D could be any letter). Is there an easy way to isolate just the letter?
String To Function Name
I am trying to evaluate a string as a function
ActionScript Code:
var tops = "hideCP"+ "tops()";
I would like that to be read as a function the final step will be.
ActionScript Code:
var tops = "hideCP"+ e.target.name + "()";
I want to pull the name of the xml file dynamically. Thanks any help appreciated.
String As Function ?
Hello!
I have an XML for the items on a menu. I'd like each item call a different function, and have the function name written on the xml.
How would you approach this? Something like (my_str as function) or maybe using eval??
Regards
Pier
How Can You Use A String Value As A Function Name?
I have a function set up that returns a string. I then want to use this string as the part of the function name for my next function call...
Code:
function onClicknav(event:MouseEvent):void {
statusreport = String(checkstatus.checkit(event.target.name));
trace(statusreport);
TraversePage.statusreport();
This returns an error because there is no function statuspage!!! There is a function called Traverse.st_bi(); and st_bi is the value that statusreport is holding (that has been returned from the previous functioncall) but I can't seem to get it to use the value of statusreport as part of the call instead of statusreport itself???
I hope you understand my dilemma - I am sure it is some punctuation I need but I dont know what it is... ? Anyone know?
Calling Function With String
I'm trying to call a function dynamically. Using an XML file, I've read a string into a variable that is in the form of a function ["_root.SetSection(0);"]. Is there any way that I can actually execute that function using that string variable? I can't come up with a solution.
Thanks
Calling A Function From A String?
hi
lets say i have a variable with a string
theFunction = "loadMovie()";
how can i make this call the function
thx in advance
cheers
My Query String Function
In case anyone was interested, here's a query-string routine I wrote that may be of some use to people. It works just like __GET(tolken) in PHP or Request.QueryString(tolken) in ASP. Just call queryString(tolken) where you want the value of a string you passed to the .swf file in URL. For example: ...src="mymovie.swf?valA=hi&valB=there"
queryString("valA") will return 'hi' and queryString("valB") will return 'there'
Below is the function definition. Just slap it wherever, the function is defined on the global scope.
Code:
_global.queryString = function(tolken) {
// Written by Gus Crawford. No usage restrictions,
// don't have to credit me, be happy and solve problems.
// The entire queryString:
var theQueryString:String = new String();
var theStart:Number = new Number(0);
var theLength:Number = new Number(0);
theQueryString = unescape(_root._url);
theStart = theQueryString.indexOf("?", 0);
theLength = theQueryString.length - theStart;
theQueryString = theQueryString.substr(theStart, theLength);
//_root.out.text = tolken;
// Good, we have the ENTIRE qstring isolated.
// now find our specific tolken
// look for our tolken name preceded by a ? or & symbol.
// look for ?tolken= or &tolken=
var valStart:Number = new Number(0);
var valEnd:Number = new Number(0);
var valLen:Number = new Number(0);
valStart = theQueryString.indexOf("?" + tolken + "=", 0);
if (valStart == -1) {
valStart = theQueryString.indexOf("&" + tolken + "=", 0);
if (valStart == -1) {
return "undef";
}
}
valStart ++;
valEnd = theQueryString.indexOf("&", valStart);
if (valEnd == -1) {
valEnd = theQueryString.length;
}
else {
valEnd --;
}
valLen = (valEnd - valStart) + 1;
var FinalValue:String = new String();
FinalValue = theQueryString.substr(valStart, valLen);
var ChopHere:Number = new Number(0);
var ChopThisLong:Number = new Number(0);
ChopHere = FinalValue.indexOf("=", 0) + 1;
ChopThisLong = (FinalValue.length - ChopHere) + 1;
FinalValue = FinalValue.substr(ChopHere, ChopThisLong);
return FinalValue;
}
[F8] Function Parameters From String?
I have this function that should take the parameters and exec a function:
code:
function execEvent(myparam:String)
{
if (myparam != "")
{
var miniarray = new Array;
miniarray = myparam.split(",");
var parameters = ""
if (miniarray.length > 1)
{
for (var z=1;z<=miniarray.length-1;z++)
{
parameters += miniarray[z] + ","
}
parameters = parameters.substring(0,parameters.length-1);
}
if (parameters != "")
_root[miniarray[0]](parameters);
else
_root[miniarray[0]]();
}
}
Then I have a function:
code:
function MyFunction (mypar1,mypar2,mypar3)
{
trace (mypar1);
trace (mypar2);
trace (mypar3);
}
Then when I run:
execEvent ("MyFunction,joe,mary,peter);
Well, I think I should get:
joe
mary
peter
But I get:
joe,mary,peter
undefined
undefined
Any clues how to tell Flash that they are separated parameters?
[F8] How Do Use A String In A GotoAndPlay Function?
Hi.
Ok this may be a simple question to answer, but I'd be dammed if I can get it to work! On the main scene I have a stop command where it pauses for a button to be pushed. When the button is pushed I want it to continue down the timeline. When it gets to the end of the timeline it will jump scene to the scene corresponding to the button that they pushed earlier.
Here's what I have so far... On the first frame I have declared a variable...
Code:
var videoplay_string;
Then when it's paused for the button push...
Code:
this.southport_mc.southport_btn.onRelease = function() {
videoplay = "southport_central";
gotoAndPlay("continue");
};
(where "continue" is a marker on the main timeline) and then finally at the end of the timeline...
Code:
gotoAndPlay("videoplay", 1)
Can anyone help? Thanks
Is It Possible To Call A Function From A String?
Hi,
Let's say that I have a function named:
ThisIsMyFunc()
Is it possible to call it using this string:
"ThisIsMyFunc"
?
I'm asking this because I'm designing a Finite State Machine in actionscript. I did it in the past, in C++, using function pointers, but since there is no pointer in actionscript, I wanted to know if I could call a function using it's name as a string.
Thanks all for your help,
Steve
Pass A Function As A String
Hello all,
I'm messing around trying to plug Robert Penner's easing equations into a tweenEngine class which imports com.robertpenner.easing.*. When a tween is called, I want to be able to pass the type of ease through as an argument.
If I pass it through as a function, it comes through as undefined (because there is no Cubic.easeOut in the class I'm calling it from I assume), so I'm trying to pass it through as a String then convert it to a function.
Is this possible? If not, How should I deal with it?
Many thanks
Cast String To Function
I have xml data that I am reading in for some dynamic Tweens. I am reading in the function as a string from the XML but when I try to use it in my Tween it doesn't work. I am trying to cast it to Function() but that doesn't seem to work. Does anybody know what I need to do?
Here is my code:
ActionScript Code:
new Tween(mc, String(oTween.property), Function(oTween.tween), Number(oTween.start), Number(oTween.end), Number(oTween.duration), true);
This same thing works if I do this:
ActionScript Code:
//change Function(oTween.tween) to null
new Tween(mc, String(oTween.property), null, Number(oTween.start), Number(oTween.end), Number(oTween.duration), true);
A little more data on this: oTween.tween = "mx.transitions.easing.Strong.easeOut";
Converting A String Into A Function Name
Hi
I try to concatenate a string to call a function but it doesn't work. There is a way to do so?
Here is my trouble code:
Code:
for (var i:uint=0; i < flowMenu.numChildren; i++) {
var mc:MovieClip=flowMenu.getChildAt(i) as MovieClip;
var a:Function = Function("on" + mc.name)
mc.addEventListener(MouseEvent.CLICK, a);
}
Function To Shorten A String
I am not to skilled when it comes to strings and as such I need
a function that will trim a html type string when it finds the
seven characters <a href
So here is what I have (you can just copy and paste into a
new flash movie to get rolling):
Code:
var theString = "<b>Movie Title</b><br>The first in a series of <b>new</b> premiers begins today in <b>...</b>Cameras at the <a href='http://www.movies.com'>ready</a> to record the action ...";
function stripHREF(myString) {
//find case of '<a href' then delete everything after and including
return myString;
}
stripHREF(theString);
trace(theString);
... So the above code should just trace the following string only
(don't worry that it doesn't make much sense):
Code:
<b>Movie Title</b><br>The first in a series of <b>new</b> premiers begins today in <b>...</b>Cameras at the
Please help if you can see what I need
Thanks,
Reflex.
Calling Function Via String Name?
Hi all,
Is it possible to call functions based on strings?
i.e.
function mainFunction( nameOfNextFunction:String ):Void{
// do some stuff here
// then call 'nameOfNextFunction' - passing some arguments
}
I figured it may be something like instance[ nameOfNextFunction ], but haven't come across anything like this in the forum. Hope this makes sense.
Many thanks,
Burt
Execute String As A Function
Hello Friends,
Can anyone guide me through this...
I want to execute a string as as a normal statement line...
for example...
var str:String = "trace('done')";
function abc() {
str;
}
I want this code to work as:
function abc() {
trace('done');
}
Please help me guys, I am in trouble...
Your help will be highly appreciated...
Thanks in anticipation...
Looking for your reply...
Passing A String To A Function
Hi I want to pass a varible (a string) to a function when I roll over a
button. I have tried this but it does not work.
var ross:String('hello');
freshnLogo_mc.addEventListener(MouseEvent.ROLL_OVER, oneRollover, ross);
function oneRollover(event:MouseEvent, ross):void {
trace('you passed' + ross);
}
Using String For Calling Function
hey guys,
have a little question:
is it possible to call a function (as my headline tells you) with a string somehow like this["myfunction()"], but i found out this does not work. Is there any hint to make that work?
Thanks,
FindAndReplace String Function
I have been in need of a find and replace function in flash for awhile now, so i whipped up one today. It works identical (almost) to PHP's str_replace() function.
PHP Code:
/**
*@description: a find and replace function that will search a string and find all occurances of "search" and replace it with "replace"
*
*@param: find, a string, or an array of strings specfying what string(s) you want to find
*@param: replace, a string, or an array of string specifying what to replace the strings found with.
*if no value is specified, a empty string ("") replace value is assumed. If there are less entries in the replace array than in the find
*array, empty string values are assumes for the rest of the replace values. This value is optional.
*@param: limit, a limit to the amount of times to exacute the find & replace operation. This value is optional.
*@returns: the string after the find and replace operations have been completed
**/
String.prototype.findAndReplace = function(find, replace, limit) {
var tempString = this, tempParts, pos, loopLength;
if(typeof(find)!=="string") {//then the find and replace is an array
if(replace === undefined) replace = [""]; //if no replace was specified
else if(typeof(replace)==="string") replace = [replace]; //if only one replace was specified
} else {//then they are a string
//put both of them in array form
find = [find];
replace = [relace];
}
loopLength = find.length; //determines the loop length
for(var a = 0, c = 0; a<loopLength; a++, c = 0) {
while((pos = tempString.indexOf(find[a]))!==-1) {
if(limit!==undefined && c>=limit) break;
//split the array into 3 parts
tempParts = new Array(tempString.substring(0, pos), tempString.substr(pos, find[a].length), tempString.substr(pos+find[a].length));
tempParts[1] = (replace[a]===undefined)? ("") : replace[a]; //if there was no replace specified give an empty string
tempString = tempParts[0]+tempParts[1]+tempParts[2];
c++; //increase the counter
}
}
return tempString;
}
How To Execute A String As A Function
Hi, I'm trying to make a function that can take a string formatted as a function command and execute it.
For example I want to take
Code:
var myString:String = "runFunction(var1, var2, var3);"
and then execute that string as a function. I've tried
Code:
eval(myString);
and didnt seem to work. Anyone have ideas on how I can accomplish this? Thanks-
Format Int To String Function?
Anyone have a good idea how I should format a long integer into string format with commas? I don't know if there's a built-in func for this, but I haven't found it.
raw int: 2000000
parsed string: 2,000,000
Convert String Var To Function()?
Is there some way to convert a dynamically loaded variable to a function name?
Something along the lines of:
ActionScript Code:
for (i=1; i<menuArray.length; i++) { var menuSelect = menuArray[i]+"Open"; menuSelect = function () { ////do something here.../// };}
Basically I have a variablethat stores a string from an Array, and I want that string to then be used as a function name... I'm not sure if this is possible, but I can't seem to get it to work.
thanks,
iLan
String Manipulation In Function
I'm using a function to call multiple button actions, so I don't have to rewrite code for each button... here's the script:
Code:
function btnSelect(num){
var btnA = "btn" + num;
btnA.onRelease = function(){
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[num], 1);
desc_txt.text = description[num];
picture_num();
}
}
}
btnSelect("0");
btnSelect("1");
btnSelect("2");
btnSelect("3");
btnSelect("4");
This is all part of a clip which loads pictures externally... each of the buttons (which are mc's) are named btn0, btn1, etc.... any ideas how to make this work??
Calling Function From String
Yeesh, no luck.
ActionScript Code:
var classRef:Class = getDefinitionByName("fl.motion.easing."+eXML.type.@value) as Class;var classInst:Object = new classRef();trace(classInst, eXML.type.@value, eXML.func.@value); // outputs: [object Elastic] Elastic easeOutvar f:Function = classInst[[eXML.func.@value]()] as Function;// error: TypeError: Error #1006: value is not a function.
classInst goes through fine (finds fl.motion.easing.Elastic and creates a new instance of that class). However, when I try to reference one of its methods, easeOut, using a string and targeting via the array method, it doesn't work. Perhaps I'm missing a set of brackets somewhere?
Thanks very much for any help...
Calling Function From String
hello,
was trying to get a prototype run from a foreach loop depending on instance name... but i stripped the code .
Why wont this work?
ActionScript Code:
myFunc = "hello"hello = function (){ trace("hello World")}eval(myFunc)
Run A Function On String All At The Same Time?
Okay....How can I put this... Okay, here goes nothing.. I have an online app that allows a user to select as many strings as they want from a dynamic textbox, then run a function on them. Can you do that without a for loop so that it runs the function on them all at once?
Please help,
-The M95
Using String For Calling Function
hey guys,
have a little question:
is it possible to call a function (as my headline tells you) with a string somehow like this["myfunction()"], but i found out this does not work. Is there any hint to make that work?
Thanks,
FindAndReplace String Function
I have been in need of a find and replace function in flash for awhile now, so i whipped up one today. It works identical (almost) to PHP's str_replace() function.
PHP Code:
/**
*@description: a find and replace function that will search a string and find all occurances of "search" and replace it with "replace"
*
*@param: find, a string, or an array of strings specfying what string(s) you want to find
*@param: replace, a string, or an array of string specifying what to replace the strings found with.
*if no value is specified, a empty string ("") replace value is assumed. If there are less entries in the replace array than in the find
*array, empty string values are assumes for the rest of the replace values. This value is optional.
*@param: limit, a limit to the amount of times to exacute the find & replace operation. This value is optional.
*@returns: the string after the find and replace operations have been completed
**/
String.prototype.findAndReplace = function(find, replace, limit) {
var tempString = this, tempParts, pos, loopLength;
if(typeof(find)!=="string") {//then the find and replace is an array
if(replace === undefined) replace = [""]; //if no replace was specified
else if(typeof(replace)==="string") replace = [replace]; //if only one replace was specified
} else {//then they are a string
//put both of them in array form
find = [find];
replace = [relace];
}
loopLength = find.length; //determines the loop length
for(var a = 0, c = 0; a<loopLength; a++, c = 0) {
while((pos = tempString.indexOf(find[a]))!==-1) {
if(limit!==undefined && c>=limit) break;
//split the array into 3 parts
tempParts = new Array(tempString.substring(0, pos), tempString.substr(pos, find[a].length), tempString.substr(pos+find[a].length));
tempParts[1] = (replace[a]===undefined)? ("") : replace[a]; //if there was no replace specified give an empty string
tempString = tempParts[0]+tempParts[1]+tempParts[2];
c++; //increase the counter
}
}
return tempString;
}
String To Function Call
hello...
i got this string that comes from a XML...
myString = '_root.testFunction(10)'
Wich is the best way to execute this function that is returned like a string from the XML?!
I got that function already defined in the first frame of timeline:
ActionScript Code:
function testFunction(arg) {
trace(arg)
}
Best regards...
Help With String.stripTag Function
I'm trying to test String.stripTag function
ActionScript Code:
String.prototype.stripTag = function():String
{
var i = this.indexOf("<");
if (i > -1)
{
this = ( this.substring(0, i) + this.substring(this.indexOf(">", i)+1) ).stripTag();
}
return this;
}
// USAGE:
var str:String = "<h1>Example of stripTag function</h1>";
str = str.stripTag();
// will return "Example of stripTag function"
found from http://www.sephiroth.it/proto_detail.php?id=184
When I publish the code in flash 8, it gives following error:
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 15: There is no method with the name 'stripTag'.
str = str.stripTag();
Function To Shorten A String
I am not to skilled when it comes to strings and as such I need
a function that will trim a html type string when it finds the
seven characters <a href
So here is what I have (you can just copy and paste into a
new flash movie to get rolling):
Code:
var theString = "<b>Movie Title</b><br>The first in a series of <b>new</b> premiers begins today in <b>...</b>Cameras at the <a href='http://www.movies.com'>ready</a> to record the action ...";
function stripHREF(myString) {
//find case of '<a href' then delete everything after and including
return myString;
}
stripHREF(theString);
trace(theString);
... So the the above code should just trace the following
string only (don't worry that it doesn't make much sense):
Code:
<b>Movie Title</b><br>The first in a series of <b>new</b> premiers begins today in <b>...</b>Cameras at the
Please help if you can see what I need
Thanks,
Pen.
String Replace Function In Flash 5...
Hi,
Has anyone written a string replace function in Flash 5? If so any chance of posting the actionscript for it? Have had an absolute ball-ache trying to get the one I'm doing to work!
Cheers,
Ears
Function Call From String (cannot Get It To Work)
I have got this small problem. For example I ve got the following code:
function test()
{
trace("it works");
}
y = "test()"; // y is a string containing the name of the test() function
Now I want to call the function test from the string y.
test(); //does work
eval(y); //does not work
x = test();
x; //does work
How can I call the function test() from the string y???
Thank you in advance,
GD
Convert A String Into Calling A Function()
Say i have a string like this: "changeAlpha()"
and i want it to become a calling function like this: this.changeAlpha();
How would one make this change? Im creating global prototypes if you wandering and when my Prototype is called, I have a var "myFunction" brought into it. like this:
MovieClip.prototype.aFunctionName = function(myFunction) {}
Cheers!
String Replacement Or Stripslash Function?
I have a swf that is calling in an xml document to run dynamic text. I need to be able to strip the out of this xml for it to work properly. Is there actionscript that will do this?
for example the xml document reads:
<![CDATA[<u><a title="Google" href="http://www.google.com/" target="_blank">Google</a></u>]]>
it needs to be interpreted by flash as:
<![CDATA[<u><a title="Google" href="http://www.google.com/" target="_blank">Google</a></u>]]>
|