Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




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?



FlashKit > Flash Help > Flash ActionScript
Posted on: 08-27-2003, 03:34 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

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?

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 ;)

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;
}

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;
}

AS2 - Casting An Object To A Different Type
Hi all,
I'm trying to convert a String to Slide (mx.screens.Slide). Everytime I'm getting null.


ActionScript Code:
var slide = "slide_11"
_root.presentation.gotoSlide(slide);


I need to do this but it doesn't work. I have a string because slide_11 was in a xml file.

Any idea?

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.

Flex Casting An Instance Object From An External Swf
Hi,

I have a custom class called GoalKeeper.as . In my external swf, i create an instance of this class like

Code:
var myGoalKeeper:GoalKeeper = new GoalKeeper()
And the from my main swf, i just make a reference to use myGoalKeeper.


Code:
var rootGoalKeeper:GoalKeeper = externalSwf.myGoalKeeper;
And when i run the main swf, i got the following error?

TypeError: Error #1034: Type Coercion failed: cannot convert game::GoalKeeper@35896381 to game.GoalKeeper.

myGoalKeeper is just an instance of GoalKeeper class, what is wrong?

Note:I develop classes in Adobe Flex and compile my projects in Adobe Flash CS3.

Converting (casting?) TextFormat Object From ComboBox
I've a textfield that can have different TextFormats applied to it - these formats are in a combo:

var comboProp:Array = [{label:"Body style 1", data:myFormat1}, {label:"Body Sytle 2", data:myFormat2}, ....etc

The listener function needs to set the TextFormat of the field to the chosen combo value:
field_txt.setTextFormat(ComboBox(evt.currentTarget ).selectedItem.data);

but I'm getting all sorts of errors - notably:

cannot convert "[object TextFormat]" to flash.text.TextFormat.

I've tried appending ....data.getTextFormat() to the end of the above but no joy. I guess this is a simple schoolboy error but if anyone can help I'd most appreciate it!

Cheers,
Pt

What's The Best Way To Parse Out A Url String Using The String Object In Flash
I'm creating a CMS(Content Management System) tool so that users can change text and the changes be reflected in a text window in flash . The text that the user enters in the CMS tool will be stored in the database.

In flash I want to parse the string that I get from the database and look for URL strings that start with http "http://www.someurl.com" and parse out that substring.

For example the string could be "Please vist my site at http://www.site.com". I would want to parse out the http://www.site.com


If I find this url string I want to pre-pend the a href tag <a> and append the closing </a> tag to the string so that this link will be clickable from the textfield.

Does flash have an object that deals with Regular Expressions?
I've looked at the String object in flash but not sure how to achieve this task

I'm currently working on this so any ideas?

Pass A String, Return Object With Name String
I feel like this should be pretty easy, but I 'm not quite sure how to do this...

I've got a string that is the name of a movieclip which is on the stage. I'd like to write a function which I can pass that string and have it return the object which has the instance name of that string.

Any hints?

Thanks.

John

What's The Best Way To Parse Out A Url String Using The String Object In Flash
I'm creating a CMS(Content Management System) tool so that users can change text and the changes be reflected in a text window in flash . The text that the user enters in the CMS tool will be stored in the database.

In flash I want to parse the string that I get from the database and look for URL strings that start with http "http://www.someurl.com" and parse out that substring.

For example the string could be "Please vist my site at http://www.site.com". I would want to parse out the http://www.site.com


If I find this url string I want to pre-pend the a href tag <a> and append the closing </a> tag to the string so that this link will be clickable from the textfield.

Does flash have an object that deals with Regular Expressions?
I've looked at the String object in flash but not sure how to achieve this task

I'm currently working on this so any ideas?

Object To String?
I have an object that reads this in the output window:

_level1.scroller.tmp_mc.instance7.cont_3.cont_1.co nt_1.cont_1.cont_1.link_1

im trying to create a function which counts how many levels there after the first "cont_". ive tryied this function, and many other simaler combinations:

function find_level(obj) {
myString = obj.toString();
i = myString.split("cont_", 2);
myStringTwo = i[1];
stages = myStringTwo.split(".");
levels = stages.length;
return levels;
}

String To Object?
Hey Folks,

I've got an easy one for ya'll...

I want to turn text into an object reference.

For example, I have:
3 movie clips whose instance names are "myMc1", "myMc2",
and "myMc3", and a text box (instance name "tb") the user
will enter 1, 2, or 3.

I want to use that text variable (1, 2, or 3) to construct
an object name to access either myMc1, myMc2, or myMc3. Code
is pasted below...

///// create either myMc1, myMc2, or myMc3
var theName = "myMc" + _root.tb.text;
///// end code

Now, how would I use theName to reference the movie clip?
I've tried new object (theName). Am I on the right track?

Thanks for the help in advance,

Tripp Lowe
The University of Georgia
School of Forest Resources
GIS Lab Manager

String To Object
How do I convert a data string to an Object in flash?

Would I just use

foo = new Object(textString)?

Specify Object, Not String... Please Look.
when i'm creating an array it's not recognizing that i am inputting the names of objects, not just strings. how do i specify that something is an obnject without creating a new object?

Xml Object To String
im having trouble converting a xml object value to a string.

I am trying to get the node value and then place the node value in an alert component (yahoo flash astra alert component).

When i try to do so i get the following error "TypeError: Error #1034: Type Coercion failed: cannot convert global@5669f101 to flash.display.DisplayObject."

i have tried xml.tostring and xml.nodeValue and neither work.


Code:
function sendBtnCLICK(e:MouseEvent)
{
var msgXML:XML;

statusMessage._visible = true;

function urlSendToPhoneLoader_complete(evt:Event):void
{
msgXML = new XML(urlLoader.data);
//traces fine and gets the value
trace("xml reads:" + msgXML);

var msg:String = msgXML.message.toString()
AlertManager.createAlert(this, msg);
}
}
why am i getting an error if i have .tostring and have datatyped it a string? What am i doing wrong?

String To Object Name
during component developing i've used this way mostly.
i think it is very usefull.

var outArr:Array;
var myString:String = "myArr";
var myArr:Array = ["part_0", "part_1", "part_2"];
outArr = eval(myString);
trace(outArr);

String To Object ?
Hello all,

I started with Flash/Actionscript a week ago, a have some programming expirience, but it seems i still haven't fully understood the oop.

I'll keep it short.
I want to fade away the movie instance: p1pic_mc
the trace tells me that the Object "test" is "p1pic_mc" but why doesn't the Tween function accept it? casting problem?

thank's for any help !


Code:
var activePlayer:Number = 1;

function done(){
var test:Object = new Object("p"+activePlayer+"pic_mc");
new Tween(test, "_alpha", none,100,0,15,false);
trace(test);
};

Object Name To String
a little example at first:
if i do trace(_root.myMovieClip) it returns _level0.myMovieClip wich is good.

is there any way to transform this "_level0.myMovieClip" to a string?
don't ask me why but i want to make a subtr on this thing.

hope i'm clear enough

thanks in advance

String In Object Name
hi, wondering if someone can help me,
i have some script in which the object name will be created from a string and now i need to call another object within the object and not sure how to do it.. here is some code:
u will see on the first line of the code an object is duplicated with a new name
and on the last line i need to change the value of an object within that new object i duplicated.. no i am not show how to do it with it's new object name, at the moment i just tried pic+i
u see on the 2nd line i am able to do it because i am able to put the object path within " ".

hope it not to confusing.









Attach Code

for (var i:Number = 1; i<fashionarraynames.length; i++) {
_root.mainboard.fashion_pics.pics.loadclip.duplicateMovieClip(("pic"+i),depth,{_x:imgpos, _y:0});
loadMovie("http://www.urlhere.com/portfolio/thumbs/"+fashionarraynames[i], "_root.mainboard.fashion_pics.pics.pic"+i+".button.img.imggoeshere");
_root.mainboard.fashion_pics.pics.pic+i+.button.imgurl.text="value here"
}

























Edited: 09/23/2008 at 03:20:58 AM by PixelPaul1

String Vs Object - ?
To ask this as simply as possible I will water down what I am trying to do.


ActionScript Code:
pwn_ab.onPress = pwn_bb.onPress=function () {    var piece = new Object(this._name);    if(piece == "pwn_ab"){        this.startDrag(false, 19, 57.4, 19, 207.4);    }


I have two buttons on the stage, pwn_ab and pwn_bb - say I press button pwn_ab, the code works just fine. The problem is, see how I have ("") around pwn_ab in the ifStatement, this means my variable "piece", is a string - how can I make the variable "piece" not a string so the code below will work? Notice I removed the (“”) from pwn_ab in the ifStatement.


ActionScript Code:
pwn_ab.onPress = pwn_bb.onPress=function () {    var piece = new Object(this._name);    if(piece == pwn_ab){        this.startDrag(false, 19, 57.4, 19, 207.4);    }

String To Object
hi everyone,
i guess there have already been dozens of people asking this question, and i am sorry to ask again, but i did not find alone:

i would like to create lots of copies of lots of different clips (the original clips are called _root.model_a, _root.model_b, _root.model_c ... ...) and then asign them a position depending on variables. i am using inside a loop:

cnt++;
duplicateMovieClip("_root.model_"+utype, "copy"+cnt, cnt);
"copy"+cnt._x = ux;
"copy"+cnt._y = uy;

then an error message tells me that the thing on the left side of the assignement "=" is not a varriable / property.
i would like it to be a property, but to do so i guess i need to transform the thing in red (a string) to the reference to the object that has the same name.

in this tutorial the problem is solved by putting the 2 critical line inside the clip that will be duplicated and by puting:

this._x = ux;
this._y = uy;

but i do not have only 1 clip that will be duplicated and i don't want to put some code in each (if that is possible).
in fact i would like to make an externall call to the object that is called "copy"+cnt instead of an internall call using this.


please tell me what i should do

String Object
I'm not sure exactly what the point of this is, but I've basically reconstructed a String object in PHP.

It requires PHP5, as it uses Interfaces:


PHP Code:



<?php

/*************************************
/* PRIMITIVE CLASSES
 * -----------------
 * 
 * Basically, this extends the default
 * functionality of primitives and
 * their related functions to be more
 * OOP. I'm not sure exactly what use
 * it has yet...
 ************************************/

class String implements Iterator {
    /* Future Features:
     * Ha! Caught up for now...
     */
    
    public $string;
    private $position;

    public function __construct ($string) {
        $this->string = (string) $string;
    }

    public function getStr () { return $this->string; }
    public function __toString () { return $this->string; }

    /** STRING FUNCTIONS **/
    
    // The destructive ones
    public function prepend ($str) { $this->string = $str.$this->string; }
    public function append ($str) { $this->string .= $str; }
    
    // The non-destructive ones
    public function strmsk ($char_list) {
        // Masks string to only contain letters in $char_list
        
        $haystack = str_split($this->string);
        $newstr = array(); // Array containing correct string
        foreach($haystack as $letter) {
            if(strpos($char_list,$letter)!==false) $newstr[] = $letter;
        }
        
        return implode('',$newstr);
    }

    // Iterator functions
    public function rewind () { $this->position=0; }
    public function current () { return $this->string{$this->position}; }
    public function key () { return $this->position; }
    public function next () { return $this->string{$this->position++}; }
        // Post-transform to include all letters in loop
    public function valid () { return ($this->position<strlen($this->string)); }
}

?>




Any suggestions for making this useful? Well, currently I find it really useful, as you can iterate through a string… I've always wanted this. But anything else?

String To Object
I have this function that receives a string which has the name of the movieClip I am attaching:

function contentsFadesin(movieFadesin:String):Void {
attachMovie(movieFadesin, movieFadesin,1);
lastSelectedMovie._visible =false;
movieFadesin._x = 369;
movieFadesIn._y = 54;
movieFadesIn._visible = true;
movieFadesIn._alpha = 2;
movieFadesIn.onEnterFrame = function() {
if (movieFadesIn._alpha<=100) {
movieFadesIn._alpha += movieFadesIn._alpha*1;
} else {
delete this.onEnterFrame;
lastSelectedMovie = movieFadesIn;
}
};
}

The movieClip is attached just fine, but then the rest of the function should fade the movie in. The problem is: the variable "movieFadesin" is passed as a string (so I can use attachMovie), but the rest of the function only accepts and "Object" variable in order to work properly.

My questions is how can I change the string value of movieFadesin into a object?

String Vs Object - ?
To ask this as simply as possible I will water down what I am trying to do.


ActionScript Code:
pwn_ab.onPress = pwn_bb.onPress=function () {    var piece = new Object(this._name);    if(piece == "pwn_ab"){        this.startDrag(false, 19, 57.4, 19, 207.4);    }


I have two buttons on the stage, pwn_ab and pwn_bb - say I press button pwn_ab, the code works just fine. The problem is, see how I have ("") around pwn_ab in the ifStatement, this means my variable "piece", is a string - how can I make the variable "piece" not a string so the code below will work? Notice I removed the (“”) from pwn_ab in the ifStatement.


ActionScript Code:
pwn_ab.onPress = pwn_bb.onPress=function () {    var piece = new Object(this._name);    if(piece == pwn_ab){        this.startDrag(false, 19, 57.4, 19, 207.4);    }

String To Object
hi everyone,
i guess there have already been dozens of people asking this question, and i am sorry to ask again, but i did not find alone:

i would like to create lots of copies of lots of different clips (the original clips are called _root.model_a, _root.model_b, _root.model_c ... ...) and then asign them a position depending on variables. i am using inside a loop:

cnt++;
duplicateMovieClip("_root.model_"+utype, "copy"+cnt, cnt);
"copy"+cnt._x = ux;
"copy"+cnt._y = uy;

then an error message tells me that the thing on the left side of the assignement "=" is not a varriable / property.
i would like it to be a property, but to do so i guess i need to transform the thing in red (a string) to the reference to the object that has the same name.

in this tutorial the problem is solved by putting the 2 critical line inside the clip that will be duplicated and by puting:

this._x = ux;
this._y = uy;

but i do not have only 1 clip that will be duplicated and i don't want to put some code in each (if that is possible).
in fact i would like to make an externall call to the object that is called "copy"+cnt instead of an internall call using this.


please tell me what i should do

Getting A String Object's Name
I'm trying to create a string method that prints a variable's name and it's value and eventually some other stuff.

string.prototype.print() = function () {
return stringname add "=" add this
}

I just don't know how to use the string's name in the function that it's calling. In other words if I had a string called defined as below:

truck = "chevy";

how would I access the word "truck" in the function?

Any suggestions?

-Maurice

String To Object Conversion ?
the movie clip color is not changing. Whats wrong in this code..can anyone help me with this????

Set("finalDir",this.path) ; //path is variable I'm getting from ASP
mc = _root.finalDir; // storing it in a local variable
myColor = new Color(eval(mc)); //mc is not null and i've checked that
myColor.setRGB(0x006666);

Any Way To Control An Object With A String Of With The Same Name?
Okay, first, the example I'm giving is not what I'm using it for so anything like "this is a better way to do that" really is not helpful at all, this is just an example.

Alright.

Within Flash I have a script that concantanates two variables into a string, I then run a script that removes unnecessary characters from the string, essentially leaving something like 'Movie1A".

On the stage I have a bunch of clips like "Movie1A" "Movie2B" "Movie3A"..etc.

Now, the string itself can't be used to control the clips...I've tried. _root.Movie1A.play() does nothing (was worth a shot) and every extrapolation there of.

Is there any way I can look up an object with the same name (in this case 'Movie1A') in hopes of being able to manipulate it (play and resize, etc).

Reason I'm doing it like that is I want to do it from one piece of script and the movie could be anything from Movie2C to Movie22D, so an abnormal amount of data would have to be used for an array or anything else.

So within my current structure, does anyone know a way to control an object with a varaible that has the same name?

This Is Very Odd... Stuff With The String Object
ok, say I do the following:
i = "test";
i.split("");
trace(i);

i should get the following in the output window
t, e, s, t

but instead i get
test

why is it doing this?

String To Object Conversion
with my gallery component i am completley changing the way it sources and handles information. i am switching from using multiple arrays to a more OOP approach. It now also sources from xml.

the xml is easy to transform into a object from the node resources, however i am having trouble with the text file input.

the string system looks like this

dir = "gallery_0:[], group_0:{gallery_0:[], group_0:{gallery_0:[], gallery_1:[], group_0:{gallery_0:[]}}, group_1:{gallery_0:[]}, group_2:{gallery_0:[]}}";


and i am trying to create an object that looks like the following.

Code:
[Object]
|[group_0]
| |[group_0]
| | |[group_2]
| | | |[gallery_0]
| | |[group_1]
| | | |[gallery_0]
| | |[group_0]
| | | |[gallery_0]
| | |[gallery_1]
| | |[gallery_0]
| |[gallery_0]
|[gallery_0]
however i am having trouble with it setting it up so it can be split into arrays and then an object. wondering if anyone could either create a code a quick code to do this or give me advice on a better string structure for spliting into an object

thanks

Using A String As An Object Placeholder
Wasn't really sure how to word the title, hard to explain this in just a few words:

Basically, I have code which checks a HitTest between a ball and various surfaces every frame. Each surface is laballed square1, square2, square3, etc, so the code just goes through a for loop checking "square" + i; each time, and that works fine. However, then when I want to find out the *rotation* of the square, it doesn't work so well. If squareCount = "square" + i;, for whatever reason, if I say squareRotation = _root.squareCount._rotation, it cant understand it (despite the fact that this should work in normal Java). Here's the code more clearly:

code:
while (i < _root.squareCount){
currentSquareCount = ("square" + i);
if(_root.square1.hitTest(this._x + radius, this._y + radius, true)){
squareRotation = _root.currentSquareCount._rotation;
}
i++;
}


This doesnt work. However, this DOES work (although defeats the purpose of the code, hence the question):

code:
while (i < _root.squareCount){
currentSquareCount = ("square" + i);
if(_root.square1.hitTest(this._x + radius, this._y + radius, true)){
squareRotation = _root.square1._rotation;
}
i++;
}

[F8] Object String Reference
hello,

I have a problem using Strings and referncing to them within a function.

I have a tick box that i have created on stage that on release makes the tick visible or not visible.

however i want to pass on that visible state to another box that has the same instance name as the 1st but with a "_1" on the end. To do this i made the instance name as a String and passed that into the function, and then referenced this using '_parent[boxName]._visible = ...' As soon as i changed the reference to a String it stops working. ANY help please. I am trying to learn to write AS using relative code and not absolute, also i want to insert this AS principle into a larger project that will have 20+ of these check boxes.

The TickForum.fla is the work in progress, the tick working3 is just to help explain what i am trying to achieve visually.


Code:
function tickBox(myName:String){
var PrintBoxName:String = myName + "_1.mcTick";

trace(myName);
trace(PrintBoxName);

if (_parent[myName].mcTick._visible == false){
_parent[myName].mcTick._visible = true;
_parent[PrintBoxName]._visible = true;

trace("visible = true");

}
else if (_parent[myName].mcTick._visible == true){
_parent[myName].mcTick._visible = false;
_parent[PrintBoxName]._visible = false;

trace("visible = false");
}

}




/************************************************************
Call functions
*************************************************************/

leu1.onRelease = leu2.onRelease = function () {
var target:String = this;
trace(target);
tickBox(target);

}

[MX04] String To Object
I have this function that receives a variable that has a string value which has the name of the movieClip I am attaching:

function contentsFadesin(movieFadesin:String):Void {
attachMovie(movieFadesin, movieFadesin,1);
lastSelectedMovie._visible =false;
movieFadesin._x = 369;
movieFadesIn._y = 54;
movieFadesIn._visible = true;
movieFadesIn._alpha = 2;
movieFadesIn.onEnterFrame = function() {
if (movieFadesIn._alpha<=100) {
movieFadesIn._alpha += movieFadesIn._alpha*1;
} else {
delete this.onEnterFrame;
lastSelectedMovie = movieFadesIn;
}
};
}

The movieClip is attached just fine, but then the rest of the function should fade the movie in. The problem is: the variable "movieFadesin" is passed as a string (so I can use attachMovie), but the rest of the function only accepts an "Object" variable in order to work properly:
movieFadesin._x = 369;
movieFadesIn._y = 54;
etc...

My questions is how can I change the string value of movieFadesin into a object?

Give An Object The Name Of A String Value.
Hi. Im pretty new to as3 so this may sound pretty stupid.
Im trying to asign an object the value of a string as its name.


Code:

for(i=0;i<5;i++){
name = "myCard"+i;
var this[name]:Card = new Card();
}
is there a way i can do this?

Forsan

Object Path To String
Hi all,

I've been looking for a nifty function to convert the path of an Object to a String, but with no luck.

Example:

items.item[2].name //Object type

to...

"items.item[2].name" //String type


Anyone seen one?

Thanks

Nick

Creating An Object From A String...
Hi,
I'm currently trying to create a game object from a string.

This is the syntax I use:


Code:
var baseObj = new ["BaseObject"](_object);
The class name is BaseObject. This method does not work. Im trying to create object that way because I want to create objects from a text file.

Does anyone knows a better solution on how to create a new object using a string?

Thanks,
Steve

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.

Create An Object With Name From A String
I'm having some difficulties to describe my problem, but I hope someone still understands it
I have a method called switchPage which receives 1 String parameter (the classname of the Object that should be created). The problem is that I don't know how to make that String into a new instance of an object with the parameter name.

Here's an idea of basically what I want to accomplish.

ActionScript Code:
private function switchPage(pageID:String):void
{
    var contentPage:pageID = new pageID();
}

How I Can Reference To Object By Its String Name?
Hello,

I need to get reference to object by it's STRING name. How it can be done?

ActionScript Code:
someVariable = new Object():Object;


anotherCopy = getValue('someVariable');

so what function instead of getValue I must to use to get the value of someVariable?

Converting String To Object
Hi all.
I'm trying to convert a String into an Object, but it's not working.

When I'm trying to make the String become an Object, it's still remains a String.
I've also tried using the eval function, but it did nothing, and only returned "undefined".

How can I make this String become an Object:








Attach Code

{metadata:{listLength:2},response:[{name:"Moshe",id:200},{name:"Dudu",id:202}]}

Changing An Object Name To A String
Is there any way to do this?
Say I have a global variable called yarr:
_global.yarr = textbox;
and I want to change that in to a string, I want to change it to "textbox" instead of textbox. Is there any way to do that?

How To Create Object With String?
Hi all,

Is there anyway to create an object with a string?

For example :
var myClassString:String = "myClass"; // myClass is my real class

then create an object with something like :
var myObject object = new myClassString(); // I need to create the object from the string ....

Anyone please? Many Thanks in advance.

Best Regards

Can A String Be Converted To An Object Name?
- I have multiple mxml elements: " ... id="myName1, id="myName2 ... id="myNameN>
- I want to call a function to act on all these elements such as ...

function doSomethingRepeatedly () {
for ( ... ) {
var thisName:String= ... concatenate "myName" & sequential numbers
doSomething(thisName)
}
}
function doSomething(whichElement) {
... convert the string contained in "whichElement" to an object name "thisElement"
thisElement.someProperties=someData
}

1) Can I convert the string input to an object this way?
2) Is there a better way to do this?

Thanks in advance for any help.

Changing An Object Name To A String
Is there any way to do this?
Say I have a global variable called yarr:
_global.yarr = textbox;
and I want to change that in to a string, I want to change it to "textbox" instead of textbox. Is there any way to do that?

How To Create Object With String?
Hi all,

Is there anyway to create an object with a string?

For example :
var myClassString:String = "myClass"; // myClass is my real class

then create an object with something like :
var myObject object = new myClassString(); // I need to create the object from the string ....

Anyone please? Many Thanks in advance.

Best Regards

Copyright © 2005-08 www.BigResource.com, All rights reserved