  | |  | creating instances on the fly | creating instances on the fly 2005-10-24 - By Becky Kinney
Back To give each instance a new name, you can create a variable with a numerical value, and increment it each time, like this
instanceNum++; newName="wk"+instanceNum; _root.attachMovie("wk",newName, instanceNum);
Note that I also used the instanceNum to set the depth of the new instance, since if you continue to use 2, each instance will overwrite the previous one.
You can also let Flash pick a level and name for you like this
instanceNum=_root.getNextHighestDepth();
//then continue as above.
To set the initial position, you use the initObject, which for some reason you are now setting to "". The initObject can be used to pass any properties your wk clip possesses, including the built-in properties _x and _y. There are two syntaxes you can use:
myInit=new Object();//create initObject explicitly myInit._x = 45; myInit._y=200; _root.attachMovie("wk",newName, instanceNum,myInit);
or the shorter but somewhat harder to read:
_root.attachMovie("wk",newName, instanceNum,{_x:45,_x:200});//create the initObject using the curly bracket notation
Becky
-- -- Original Message -- -- From: "edwardsdia" <edwardsdia@(protected)> To: <pro_flash@(protected)> Sent: Monday, October 24, 2005 5:17 AM Subject: [Pro Flash Users] creating instances on the fly
> Hi all, > this is my first post here! > > I am new to actionscript, just started learning it few days ago > > what I'm trying to do is the following: > I created a movie clip symbol in the library, and I placed one > instance of it(List's call it instanceX) on the stage, now i want to > create a new instance whenever the user clicks instanceX, I used the > following code: > onClipEvent(mouseUp) > { > initialization = ""; > _root.attachMovie("wk","wk001",2,initialization); > } > > now when I click my instance X i get a new instance placed at the > upper left corner of the screen > > my questions are: > - How can I give every new instance a special instance name? > - How can I control where the new instance is placed? let's say when > the user clicks instance X then the new instance will follow the mouse > until he clicks a target place. > - I have some action script that I want to attach to the new > instances, the action script is stored in an external file "my_control.as" > > thank you > Edwards > > > > > > > > ========================= > Pro_Flash: Professional Web Developers Using Macromedia Flash > To subscribe: mailto:pro_flash-subscribe@(protected) > To UNSUBSCRIBE: mailto:pro_flash-unsubscribe@(protected) > > Yahoo! Groups Links > > > > > >
-- ---- ---- ---- ------ Yahoo! Groups Sponsor -- ---- ---- ---- --~--> Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life. http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/IHFolB/TM -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----~->
========================= Pro_Flash: Professional Web Developers Using Macromedia Flash To subscribe: mailto:pro_flash-subscribe@(protected) To UNSUBSCRIBE: mailto:pro_flash-unsubscribe@(protected) Yahoo! Groups Links
<*> To visit your group on the web, go to: http://groups.yahoo.com/group/pro_flash/
<*> To unsubscribe from this group, send an email to: pro_flash-unsubscribe@(protected)
<*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
Earn $52 per hosting referral at Lunarpages.
|
|
 |