Actionscript 3.0 :: Duplicate Sprite Instance - Create A Number Of Duplicates Of The "Player"?
Mar 18, 2011what script i need to add to the code below to create a number of duplicates of the "Player"?
[Code]....
what script i need to add to the code below to create a number of duplicates of the "Player"?
[Code]....
I am trying to get up to speed on AS3.
I am trying to dynamically create a number of click buttons based on the content of an XML file.
So I have a MC (window_mc) which contains a single button (more_details_btn). I add an event listener to send the user to a web page on click.
However. On some items I need more than 1 more_details_btn's. What is the best way to duplicate this MC and assign a new click event and different text.
Below is the code I am currently using and it is causing me all sorts of problems
Code:
for each(var detail:XML in productXML.details) {
var btn = new more_btn_cls();
btn.label_txt.text = detail.@name;
[code]...
Firstly, it wont assign btn.label.text - it says it "Cannot access a property or method of a null object reference" btn in this code traces as an object not a movieclip is that why?
The other problem is that window_mc.addChild(btn); does nothing, yet if I take away window_mc it does add the clips to the Stage. (I need them inside window_mc though)
I know I can create instances from a string like this:
var classFromClassPath:Class = getDefinitionByName(classPath) as Class;
var instance:Object = new classFromClassPath()
I know I can call some function with a parameter array like this
var x:Function = someFunction;
x.apply(null,args);
But does anyone know if I can pass parameters like that when I construct a class?
My problem is that when I click the letter movieclip it does create the duplicate as it should and it starts to drag the duplicate mc. However, when I release the clip it doesn't stop dragging? I realized that if I put onMouseUP event instead of onRelease it actually does stop dragging when I release the mouse. I would, however not like to use the onMouseUP event if possible.
[Code]...
If I have an object that calls
addEventListener(Event.ENTER_FRAME, update);
addEventListener(Event.ENTER_FRAME, update);
will that add 2 listeners?
I am making a drag and drop game using AS2 in Flash CS5 where mc items are duplicated and enlarged from a menu and can be placed anywhere on the stage to create a custom robot. Each part (arms, head, feet, etc.) is it's own mc with unique instance names. I have the drag and drop part all figured out, and I even have the duplicateMovieClip part working...
HOWEVER... Whenever I move from the current frame that an object was duplicated in, to another frame and then back, the clips dissapear one by one if you try to create a new one. Each list of menu items are in their own frames (heads, torsos, arms, etc.). As the duplicates are made, they remain on stage no matter what frame you go to and can still be dagged around, which is good, but as I said previously, they dissappear when you create a new duplicate. Not all disappear at once, only older created duplicates disappear as you bring in new duplicates.
[Code]....
[Code]....
I changed the code a bit because I would like it to work like this...If I put my mc (photo) in the center of the stage, it would creat dups every 125 pixels. But this script only makes one duplicate, I must have done something to mess it up. Idealy I would like to have the mc create dups in both directions; x and -x.
I currently have a class that has a method that creates new duplicates of a clip on the screen, changes some of their properties (such as color, and text display), and then arranges them in a straight column. Inside that method, I have some clipEvent Statements for each button.
[Code]...
I am trying to duplicate a sprite that I loaded a bunch of images in from an xml.
I even tried senocular's way of duplicating display objects and it just returned an empty sprite.
I have a for loop which duplicates movieclips. To call/create the new clips, I use this:
[Code]....
On line 72 of DragGame.as, I have the following function which should place a copy of the selected movieclip in the container_mc movieclip:[code]I don't get any errors on publish but when I click a movieclip I get the following message:[code]I've tried rewriting this function over and over to no avail.
View 3 RepliesI have a movie clip, that has various codes attached to it to snap to areas of the screen. If I apply the duplicate movie clip command to this, the second instance will have a new name right? so how can I change the code that addressed the original movie clip to relate to the new instance with the new name?
View 5 RepliesI haven't seen much to explanation of this in any Flash documentation,but maybe someone knows more about this. Initially I was trying tofix a buggy application. The app is fixed now, but I'm still curious.I have an app that defines some object instances (buttons and movie clips)in various frames and on various levels of a timeline. For any object thatneeds to be manipulated by AS, I give it an instance name. However, there's no safeguard against giving several instances the samename. So, I experimented with giving two buttons, on differentlayers and different frames, the same instance name ("playbtn"). Then I defined an event handler:
playbtn.onRelease = function () {
gotoAndPlay(1);
}
[code]....
Ive made a FLA that has 360 frames.. on each frame there are 5 instances of a movie clip, each of which ive had to painstakingly position and adjust the perspective of with the 3d tool to make them look like they rotate with the clip. Each of the 5 instances on the stage have different instance names (screen1_mc - screen5_mc).My problem is, after all that frame by frame positioning, ive gone to render out the SWF and its telling me that there are "Multiple 3D objects on the same frame have the same instance name. 3D instance names must be unique. All but one of the instances will be renamed during export."
Soo frustrating. I must have either hit ctrl+v twice on one of my frames or perhaps not renamed the instance after pasting it.. but i cant figure out which frame the problem is happening on. Im really hesitant to have to go through all 360 frames clicking on all 5 of the instances to see which frame is causing the issue.Can anyone think of a programmatical way to figure out which frame has the duplicate instance on it?I was thinking about using an enter frame event to loop through tracing out the frame number, then somehow trace out the instance names and the number of instances of screen_mc that appear on each frame to see which frame has the instance thats been automatically renamed by flash?
I have a game that needs to send the number of points a player is awarding to another player to a MySQL database on the same server. This game is part of my psych MSc dissertation, and I've gotten a lot of help on this bit from my department techie who knows php and MySQL well. However, he has absolutely no experience with Flash or Actionscript. He's gotten the php bit working so that it does send data to the right table in the database when it's supposed to using dummy variables, but when we try to test it with the actual .swf thats supposed to be doing the sending, nothing happens. We're pretty sure this means theres something wrong with the actionscript, but we don't know where.
[Code]...
My company is holding an event for our clients and I was asked to make an online flash page to help us in keeping track of the tickets.
The file would have a mandatory text field for them to enter their name (name_txt) and another to enter their email address (email_txt).
Next, they would click a generate number button (generate_btn) to generate a random number to a dynamic text field (number_txt). The number set would be 1-500.
I need actionscript to generate a number that will not be duplicated. When they click the generate button, it will submit to a form via mysql / php. The button, generate_btn, will then be replaced by a print button for them to print their number. (The number will also be emailed to them in the event they don't print it).
Now that I'm thinking about it, we would probably need to have them create a user name / login, so that they can't just return to the page and generate another number.
have a imageHolder_mc wich is calling the image from the local drive / server, and this container is inside of PictureHold_mc and that inside of Image01_btn.image01_btn.pictureHold_mc.imageHold01_mcand all this for 1 image tobe displayed in the website. But I am going to have something like 300. This is for example HomePage to ProductPage to SpecificIndividualProduct.I have created an instance but DO I NEED TO DUPLICATE ALL _btn and _mc all the way down? Or is there any better ways.And next question. I have done Home Page with 18 images called from the local drive but despite of Preloader showing 100% loaded page look empty for about 30 sec. and suddenly all images starts popping out ramdomly.
View 5 RepliesI thought since a Sprite is a display object container and I can add an instance of a MovieClip to it I should be able to reference the MC through the Sprite.
var bh1:Sprite = new Sprite(); beerChan = new BeerChan(); bh1.addChild(beerChan); trace("bh1 "+bh1); trace(bh1.beerChan);
1119: Access of possibly undefined property beerChan through a reference with static type flash.display:Sprite.
I am having trouble setting the instance name of my Sprites that get created through a for loop. What I am doing is loading an external gif into a 16 Sprites that gets created in a foor loop...but it seems like it ignores my box.name parameter setter.
[Code]...
I was taking this tutorial, >>LINK<< I want to change it from,
Code:
on (click) {
Duplicate Movie clip to,
Code:
onClipEvent (Load) {
That way once it load's it will duplicate the circle MC a random number of times. This circle MC is inside of another MC so it wouldnt be _root i want it to goto, it would be t_mc that I want it to look for it in.
So in the t_mc MC I put this code,
Code:
onClipEvent (load) {
i = i + 1;
duplicateMovieClip (t_mc.circle, "circle" + i, i);
}
And on the circle, I put this code,
Code:
onClipEvent (load) {
scale = (random(100) + 50)
this._x = random(250);
this._y = random(150);
[Code] .....
my functions in this fla i have. I use the function to create a random number and the char move accordingly depending on the number.
View 4 RepliesI've looked over many forums and pages to sadly learn that you can not reset/change the registration point of a movieclip dynamically. Though I am curious if or how I could go about assigning the registration point to a sprite instance I create at runtime. To give you a more concrete example of what I'm doing:
I create an instance contentWindow in my code to be animated (a 300px by 200px rect with registration in the top left corner)I create a Sprite instance imageHolder in my code and add it as a child to contentWindow I then add various images to imageHolder through a Loader object referencing an XML file. imageHolder's top left corner is oriented to contentWindow's registration point. (Leaving me with an oddly oriented imageHolder if the contentWindow's registration is centered, and will only re-size from that origin) Since imageHolder will be switching out various sized images it would be much more aesthetic to have the sprite's registration point centered. So since as3 defaults it to top left shouldn't there be a way to alter it at instantiation of the sprite? Then I could set my contentWindow's registration to center and the empty sprite would center all content loaded into it?
When you email an MP3 to Posterous, it gets automatically converted into this nice player for display on your blog:
Assuming I have a place to host the MP3, what's the best way to duplicate this on my personal site? E.g., are there any slick free flash MP3 players? How hard would it be to build my own?
I have a base class I've used on 6 different MC's. Then when I use these MC's my function runs an if statement to check which one to add.
if(id=design) var obj = new design();
if(id=team) var obj = new team();
I want to make it a bit more dynamic and use the id:String to evaluate which new instance to create.
ActionScript Code:
public function loadChapter(id:String):void {
var obj = new instance_of( id )();
}
I'm loading some external assets with the Loader class. I've done this a lot over the years, but seem to be coming across a problem I haven't had before. I want to display two instances on the stage at the same time of a .png I'm loading externally. If I use the Loader instance's contentLoaderInfo.content object in more than one sprite, the bitmap just "moves" from the first instantiated sprite to the second. I've tried duplicating the sprite with Senocular's duplicateDisplayObject class, but for some reason, it's not working right. But shouldn't I be able to use multiple instances of an imported bitmap like this just as if it were in the library of the .fla? If so, what do I need to do?
View 3 Replieshow to swap the sprite instance for a movieclip via the document class.
this a boid example from soulwire, and works great but i want to use a library clip instead of the vector sprite - for arguments sake - the library clip would be "boid"...
[Code].....
but am not able to work out what i need to add/edit...
im trying to make a tile map. is there a code for Flash Player 10 to Duplicate an DisplayObject?
View 4 RepliesMy assignment is to create a real time (meaning using a game loop) Flash game in an object orientated manner. I've been following guides online, and I think I've got the basics down, but my player sprite isn't appearing.
I imported an image into Flash and then converted it into a symbol called Player, and now it's a movie clip. I exported it for ActionScript, and called the class com.Player.
Also, I have set the class of my document to com.Engine (this is where I plan to have my game loop and call methods to other classes).
Then, I created a directory called com in the same directory as my .fla. Inside that directory, I made Engine.as and Player.as, and here's the code for them both:
package com {
import flash.display.MovieClip;
import flash.display.Stage;
[Code].....
According to what I know, that should make the player appear in the center of the screen when I run it, but it doesn't. I've verified that the Engine class and constructor is being called using trace("hello world"), and I get that output. I also know that the constructor for the Player class is being called by using the same method. I just don't get why the player doesn't appear on screen.
If I drag the Player symbol (correct terminology?) from my library onto the stage, the player sprite shows up... so I know there's an image attached.
I am really not sure what to call this problem / search for to view an old solution. So if I am being redundant, simply link me to an old thread / lock this.[code]...
View 2 RepliesI have a movieclip that when clicked returns a [object MovieClip]
function down(event:MouseEvent):void {
trace(event.currentTarget); // returns [object MovieClip]
}
what I would like to do is create a dulplicate of this.