ActionScript 3.0 :: Dynamically Naming/referring To Movieclips?
Feb 15, 2010
I am going to have a button that when you click on it it creates a movieclip and adds a certain child to it (In this case, its linkage is set as "Rifle"). Each time you click on the button I need to give the new movieclip a different instance name then the last, such as "Riflemen1", "RifleMen2" etc.. I will need to be able to refer to each movieclip seperatly in my code, such as for example:
You spawn three Riflemen.. You click on one of them, which selects it, you then click on an "Attack" button which makes only him start firing (in my case gotoAndStop(2)), you then decide you want the third one to attack and so forth..
Ok, I've been climbing the walls trying to figure this out, looked everywhere for an answer, learned a few bits and pieces along the way, but still can't do it.I've made my Class which is a little movieclip called 'block', it's fine and does what I tell it to do ie. I can reposition itstretch itotate it and stuff.The problem is.. I want to make more of them and reference them individualy so I can change the properties of them individualy ie, the x and y values etc.
for (var i=0; i<2; i++){ var newBlock:blocks = new blocks(); this.addChild(newBlock);
I have a movieclip on the stage in which I have some 90 movieclips also on the stage.
I created an array to hold the movieclips. But when I try to add eventlisteners to these movieclips by cycling through the array, I get a 1009 error ("Could not parse the XML. Error #1009: Cannot access a property or method of a null object reference.") Oddly, however, the application seems to work correctly, handling my listener events.
On the other hand, if I add eventlisteners for each movieclip individually, all works fine--no errors are thrown.
I'm trying to dynamicly create movieclips that I can drag and drop. Here's what I'm trying to reproduce dynamically: (I placed 2 movieclips on my stage and named them mandible_mc and vertibral_mc)
mandible_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);mandible_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);vertibral_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);vertibral_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt); function pickUp(event:MouseEvent):void { [Code] .....
Here's what's happening: Unless I have actually placed two movieclips on the stage and named them mandible_mc and vertibral_mc, I get an error. If I DO have those to movieclips on the stage, I get no error and I get my instances of "name_box". But, I can't drag them. I CAN drag and drop instances of mandible_mc and vertibral_mc so I know the addEventListener and buttonMode "thingys" are being created.
I am reading a file with certain user defined variables like &x=30&y=50&z=100
Lets the variable is caught in a function as argument myVar
now depending on the variable the user passes I need to fetch the value. ie if the user passes x i need to read the value of x. how the user has named his/her variables.
What i need to do it get the value of that variable by using loadVar.
this.myVar; As such it gives me undefined. There is text present in 'this' myVar represents 'x' I have tried eval(this.myVar) as well as this.eval(myVar) but in vain
I'm creating a DDR style game. The 'moving graphics' are being randomly and dynamically created with the default instance name (instance28, instance 30...) I want to be able to refer to these different elements according to another movie clip I press (in this case, they look like piano keys).
So, if a 'C' moving graphic is created, I want the C movie_clip with a listener attached to check the 'C' moving graphic.
Code: public function btnU1Out_Handler (event:Event ):void {btnUOut_Handler(1);} public function btnU2Out_Handler (event:Event ):void {btnUOut_Handler(2);}
I am doing the following Code: Select allvar a:MovieClip = new MovieClip(); addChild(a); Now what I want to do is I want to create six more mc i.e., a2,a3,a4,a5,a6. I want to accomplish this using loop like this: Code: Select allvar i:Number = 0; while(i < 6){ var a:MovieClip = new MovieClip(); addChild(a); }
So with above method how can I give different names link above to var a? Then I am using all of these var as following: Code: Select allvar cube:Cube = new Cube(new MaterialsList({ front:a , left:a2, right:a3, top:a4, bottom:a5, back:a6}),200, 200, 200,10, 10, 10); scene.addChild(cube); How can I use those dynamic name here?
i am using a loop function to generate an place instances of a movie clip on the stage. the movie clips are being used as buttons, they have text in them. here is the code
ActionScript Code: // butAniMini is an external custom class animating the buttons var _sideBarBut:butAniMini; //variables to hold the first buttons x an y position
[code]...
the problem is that i dont no how to set the text in the buttons so u can change the text and add event listeners etc to them
I have a project that requires manipulation of a movie clip (swf file). This clip is called clip_mc.I have functions such as:[code]If I add to the stage the swf and call it clip_mc, then everything is fine and it all works - BUT I have a few of these files that need to be loaded when the button is clicked.I understand the loader() class and the addChild class but cant get my head around bringing them all together!so essentially I would like to know; How to dynamically load the swf and name it clip_mc so that the functions will work?!
I received help on this site on this info-graphic im doing and the solution was to use an "array" which im not familiar with at all. the person that helped me added the following code that worked:
var city_arr:Array = new Array("louisville");//filll that array with all nedded cities//make all the boxes invisible at startfor (i=0;i<city_arr.length;i++){ var [code]...
since i dont know how to use arrays im stuck. i need to add at least 30 more cities to my info-graphic but don't know how to use the naming conventions of an array.Only one of the houses works (when you click on it a pop-up appears, is draggable and has an x to close the pop-up)
I'd like to know how I can achieve this in AS3. The code would work fine in AS2, but as I am very new to AS3 I am not sure what the equivalent would be in AS3.
I'm working on a project so as to hopefully learn AS3 a bit more, and for it what I have for it currently is that it looks at the time, and if its between 8 pm and 8 am it imports one mc, or if its between 8 am and 8 pm it imports another. My problem at the moment is that I can get it to import it and align it at the needed x coordinates, but not the needed y coordinates. I'm not sure what the exact y coordinates are, but as in the future they might change, I was trying to find a way to align it so that the very top side of the mc to the top side of the stage, but so far I have had no luck, as I can't think of what would be needed. I've seen references to a "StageAlign._______" before, but either I'm not using it right or it isn't the right thing to use.
Here is my code right now: ActionScript Code: import flash.events.* import flash.display.StageAlign; import flash.display.StageScaleMode; var time:Date = new Date(); [Code] .....
Im trying to dynamically add several of the same movieclips to the stage. This movie clip contains a textbox. I have tried the following:-[code]I have my movieclip exported fror actionscript with the identifier as (textbox). This code does add a textbox to the stage however it only adds the second one which says "goodbye" but not the first one which should say "hello"? I thought the loop should go round twice and add a 'newText1' and a 'newText2'??
i wanted to create a bunch of movieclips in a for loop but wanted to name them something different each time, how would i dynamically name them? example of basically what i want to know how to do
I have a little problem with a loop. I recieve som data from a database and gets it back as an array. I then use a loop to add movieclips dynamicly and this works fine to, but if i try to trace the id from an onRelease function i get an undefines, but when i dot it outside the onRelease it works fine. This is the code. Its in a class by the way.
I have about 70 MovieClips and when you rollover one I want it to enlarge and the other MovieClips' x & y to shift so that nothing is overlapping. Does anyone know how to do this or has anyone seen an example? I have attached some screen shots of how I would like this to work.
Is there any way to create dynamic animations? Say if I'm creating a game and there might be multiple sprite sheets for different NPC's, would I have to manually create the walking/whatever other animations manually?
Movieclips created on the stage and instanced behave differently from dynamic movieclips in that they are destroyed when you go to the next frame (I have a stop on every frame). If I create that same movieclip dynamically then it will stay on the stage forever regardless if I go to the next frame or not. I understand that it needs to be removed from the display list but I can't find any event that is fired on a next frame basis. I could use onEnterFrame but at 30 fps, that's alot of overhead. The idea is to have all the code contained in my .as file.
I'm looking to be able to pick up one of 36 movieclips on the stage, and drag it to a hotspot. If it lands on the hotspot, then it does something, otherwise it just gets dropped.
How do I dynamically change the "target_mc" to be whichever movieclip I select?
This code works fine, but that's because eventlistener is set-up explicitly for a given mc.
Code: // sprites import caurina.transitions.*; var drag_mc:MovieClip = energy_sprites.play_wave;
I have an application that I am adding movieclips to a container movieclip through a for loop and repeatedly calling myClip.addChild(theNewClip). Now I have a dozen clips in my container and it seems like the only way to access the clip is to use the getChildByName() method and cast it into a temporary clip so I can get at the its properties.
Is this the best and/or only way to do this? Does the old AS2 myContainer["theName"].property not work with dynamically created movieclips? It doesn't seem to work for me anymore.