Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-07-2009, 06:16 PM   #1
dogcollarlabor
Registered User
 
Join Date: Nov 2009
Posts: 2
Default Dynamic naming or whatever it's called

Hi all, first time posting, long time lurker. Thanks for the great forum.

I'm curious if there is dynamic naming for variables, arrays, functions and whatnot in AS3. Below are Perl examples of what I'm asking about. It should be pretty explanatory.

Thanks again,
Doug

$varOne = 'dog';
$varTwo = 'cat';

@arrayOne = ('dog','cat');
@arrayTwo = ('fish','frog');

sub subOne { print "anything"; }
sub subTwo { print "anything else"; }

$varDyn = 'One';

print ${'var'.$varDyn};
#result = dog

&{'sub'.$varDyn};
#result = anything

print ${'array'.$varDyn}[1];
#result = cat

${'varTest'} = 'bird';
print $varTest;
#result = bird
dogcollarlabor is offline   Reply With Quote
Old 11-07-2009, 08:53 PM   #2
nunomira
Senior Member
 
Join Date: Mar 2003
Location: portugal
Posts: 228
Default

hi,

In ActionScript you have array notation:
ActionScript Code:
var myString:String = "my"; var myVar:String = "dog"; trace (this[myString+"Var"]); // dog var myArray:Array = new Array("cat", "dog"); trace (this[myString+"Array"][0]); // cat function myFunction():void {     trace ("myFunction called"); } this[myString + "Function"](); // myFunction called

Last edited by nunomira; 11-07-2009 at 08:57 PM..
nunomira is offline   Reply With Quote
Old 11-07-2009, 08:57 PM   #3
nunomira
Senior Member
 
Join Date: Mar 2003
Location: portugal
Posts: 228
Default

If you have a DisplayObject on the stage, you can also use getChildByName():
ActionScript Code:
var myString:String = "some"; var mySprite:Sprite = new Sprite(); mySprite.name = "someName"; addChild(mySprite); trace(getChildByName(myString+"Name")); // [object Sprite]
nunomira is offline   Reply With Quote
Old 11-07-2009, 11:57 PM   #4
dogcollarlabor
Registered User
 
Join Date: Nov 2009
Posts: 2
Default

Thanks a bunch nunomira, that will help a lot.

Doug
dogcollarlabor is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:50 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.