Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-23-2007, 10:46 AM   #1
ImLostAgain
ImLostAgain
 
Join Date: Nov 2007
Location: Downtown
Posts: 1
Default using [] instead of eval() in AS3.. still dont work

Hi,

I have a MovieClip in libary Exported as: myMC.
Now, I wanna attach it to the flash at runtime.. in AS2 this would be easy using attachMovie and eval functions. But how to do it in AS3?

ActionScript Code:
var i:Number; var makeTotalMc:Number = 10; for ( i=1; i<makeTotalMc; i++) { var addedMC[i]:myMC = new myMC(); this.addchild(addedMC[i]); }

What am I doing wrong? Please help me with this code while I'll bang my head against the wall

Last edited by dr_zeus; 11-26-2007 at 06:19 PM. Reason: added [as][/as] formatting tags
ImLostAgain is offline   Reply With Quote
Old 11-23-2007, 10:56 AM   #2
mooska
fl.mooska._title
 
mooska's Avatar
 
Join Date: Jun 2006
Location: lodz
Posts: 1,211
Send a message via ICQ to mooska Send a message via Skype™ to mooska
Default

ActionScript Code:
var mc:MovieClip = new MyMc(); mc.name = "something"+i; addChild( mc );
or
ActionScript Code:
var collection:Array = []; for ( i=1; i<makeTotalMc; i++) { var mc:myMC = new myMC(); addchild(mc); collection.push( mc ); }
?
__________________
pebkac - problem exists between keyboard and chair

Have something to code ?

asql
mooska is offline   Reply With Quote
Old 11-23-2007, 10:59 AM   #3
gprime
Registered User
 
Join Date: Aug 2007
Posts: 9
Default

And then I think you can access your movieclips with:

Code:
this["something" + i]
But I could be wrong. I'm a noob
gprime is offline   Reply With Quote
Old 11-23-2007, 01:06 PM   #4
john c murphy
Registered User
 
Join Date: Nov 2007
Posts: 18
Default This may help

I asked a similar question in this thread:

http://www.actionscript.org/forums/s....php3?t=153155
john c murphy is offline   Reply With Quote
Old 11-23-2007, 03:48 PM   #5
Slowburn
[Invent:Design:Create]
 
Join Date: Sep 2002
Location: Toronto, ON
Posts: 2,068
Default

to get your child clip, use

ActionScript Code:
var myClip:MovieClip = new myMC(); myClip.name = "something"; addChild( myClip ); // to get your clip var myClip:MovieClip = getChildByName( "something" ) as MovieClip;
__________________
o Please do a search before you post
o Please use the [ as][ /as] tag for your code (so we can read it clearly)
Slowburn is offline   Reply With Quote
Old 11-23-2007, 04:20 PM   #6
drc
Registered User
 
Join Date: Nov 2007
Posts: 10
Default

Quote:
Originally Posted by Slowburn View Post
to get your child clip, use

ActionScript Code:
var myClip:MovieClip = new myMC(); myClip.name = "something"; addChild( myClip ); // to get your clip var myClip:MovieClip = getChildByName( "something" ) as MovieClip;
let's say in my situation MC is the parent, would you simply repplace addchild by addparent?

also, after i make mc my parent, can the child be a button that if pressed executes the parent?
drc is offline   Reply With Quote
Old 11-23-2007, 04:53 PM   #7
matbury
What's up pussycat?
 
matbury's Avatar
 
Join Date: Dec 2006
Location: Toronto, Canada
Posts: 1,990
Default

I think mooska's suggestion is the most versatile to go with:
ActionScript Code:
var myMovie:MovieClip; var items:uint = 10; var myMovieArray:Array = new Array(); init(); function init():void { for(var i:uint = 0; i < items; i++){ myMovie = new MovieClip(); // set myMove's properties addChild(myMovie); myMovieArray.push(myMovie); } trace(myMovieArray); selectRandom(); } function selectRandom():void { var rnd:uint = Math.floor(Math.random() * items); trace(myMovieArray[rnd] + "removed from stage."); removeChild(myMovieArray[rnd]); }

P.S. Using getChildByName() can be problematic.

P.P.S. In the heirachy of the DisplayList, only parents can addChild() or removeChild(), which is why removeChild(event.target) doesn't work. You need:

ActionScript Code:
event.target.parent.removeChild(event.target);

But that's another thread...
__________________
http://matbury.com/

Last edited by matbury; 11-23-2007 at 04:58 PM.
matbury 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tweens don't work on AS2 swf's loaded by AS3 swf's the second time conradoplg ActionScript 3.0 3 12-31-2008 12:43 AM
Rain Class to standard AS3 didn't work Glen Charles Rowell ActionScript 3.0 0 08-28-2007 11:12 PM
How do I get this AS1 link to work in AS3? fourtytwo ActionScript 3.0 9 08-21-2007 06:04 PM
Variable Scripting Problem ds.pixeled ActionScript 2.0 6 04-16-2005 12:26 PM
unescaping html oddballs from xml sent from flash to PHP Philip Toews Server-Side Scripting 30 06-01-2003 02:27 AM


All times are GMT. The time now is 07:40 AM.

///
Follow actionscriptorg on Twitter

 


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