ActionScript 3.0 :: How To Clone A Sprite
May 27, 2008there's a way to clone a sprite? It's easy enough with a bitmap since BitmapData can be cloned.
View 10 Repliesthere's a way to clone a sprite? It's easy enough with a bitmap since BitmapData can be cloned.
View 10 RepliesHow do I make a clone of a Sprite or MovieClip at runtime? So that if I make changes to the copy, the original remains unchanged.
And you can turn any Sprite or MovieClick in a class? So that I can create instances of this class (using new) and thus create copies of the display objects.
I created a class, extended the sprite class, and now in the constructor I am trying to set the Sprite's width and height properties which are inherited from the DisplayObject. However, after I set this.width and this.height, and print the values, I get 0 for both.
What the heck is going on? When I view the livedocs I see that DisplayObject has width and height listed as public properties. I have been able to instantiate a Sprite directly, and set the width and height after it's been instantiated, so I don't get it.
package {
import flash.display.*;
public class ScrollBar extends Sprite {[code].....
I've got a sprite which I want to temporarily hide... But changing the .visible property doesn't do what I expect. The code looks roughly like this:
[Code]...
I created a new AS3 document (550px by 400px) and added the following code to the first frame.
However, when I run this, I see nothing painted on the screen at all, the screen remains completely white.[code]...
This is probably a stupid question with a simple solution but I have been searching with no luck.
I created a shape and added it to the display list calling it arrowBtnL. But how do I take the same shape and clone it to another place on the stage calling it arrowBntR? I did a makeshift and just made the exact same shape again but it seems to unnecessarily take up lots of code lines and is uneconomical. Am I wrong here?
[Code]...
I'm doing a simple rotation on a sprite but there's a weird behavior where the sprite does not rotate around it's top left. I think I'm rotating along the top left of the test class instead of the sprite child. I would like to rotate the rectangle around it's top left corner (kinda like a clock hand). The code is pretty short so I'll let the code + pictures explain my problem:
package
{
import flash.display.Sprite;
[Code]....
I've read a lot of stuff about rotating around a fixed point, I've tried doing it with movieclips instead of sprites, I even copy pasted a tutorial on rotation and nothing works.
[Code]...
Then the numericStepper is drawn as if it is squished to 20% its normal height. If I pre-set mySprite width and height before adding the numericstepper, the trace output is 0,0 after adding it and it is not displayed at all. Is there some way I can make the sprite only adjust to correctly fit the numericStepper OR resize it afterwards without distorting the numericStepper component?
I have a toolbar with some cars on the left of the window, and I want to click on one element and drag it to the board creating a clone of it, but I can't do it.[code]...
View 1 Repliesi am using 2 instances of an flv, and as you would expect they arent sync'd.so how do i 'clone' an flv in AS3 so that they are exactly the same?i have seen an example, but it was AS2, i am working with AS3, cs4..[URL]
View 5 RepliesI have a lot of objects that gets loaded to the stage over time. Should I clone the objects that are already loaded or do URLRequest for all of them? Will the engine automatic pull loaded objects from cache if I just do URLRequest?
var myLoader:Loader = new Loader();
myLoader.contentLoaderInfo.addEventListener(Progre ssEvent.PROGRESS, onLoaderProgress);
var fileRequest:URLRequest = new URLRequest("myImage.jpg");
myLoader.load(fileRequest);
fileRequest = new URLRequest("myImage.jpg");
myLoader.load(fileRequest);
I was wondering if it's possible to have 2 selection simultaneously. Let me explain. I wanna be able select a piece of text within a textfield and have that selection-square displayed also on another textfield, using the
Selection.getBeginIndex() and EndIndex();
i.e. I select the 1st 5 characters of my textfield 1 and I have then the 1st 5 characters of my textfield 2 selected simultaneously.
I have a movieclip that inside have secuence of image, I will like 1000 instances of this movieclip, but I not like reload the 100 of images inside the movieclipIt is posible.That the movieclip have a child share with more objects
View 1 Repliesif i have my own custom event class when do i need to call the clone method?
View 3 RepliesIm trying to make a breakout clone which I have working however I cant figure out how to test which side of the blocks the ball hits. I woul like to have a different reaction if it collides with the right side than if it hit the bottom etc.
View 2 RepliesI need to be able to clone an object. The object is not a visual one, only having basic information (strings, booleans and integers). What I want to do is be able to get another object that is identical with the current one. Let me be more specific. I have the class RAM that has some info (like capacity and stuff like that). I have different object with different specs. let's call them ram1, ram2 and ram3.
I want a function that given an object will return another object with the same specs. I can always implement a clone() method inside the RAM class...but this isn't something portable and it won't work with other objects, for example CPUs. Is there any way I can clone an object. I already tried this: [URL] but that returns null.
Both of sprite.width and sprite.scaleX can be used for scale a sprite. Is possible sprite.scaleX depends on screen size?
View 2 RepliesIt has been a great resource of the years. No my problem. I am trying to dynamically resize a sprite that has a line drawn into it. Here is my code:
[Code]...
I need to take a jpg and clone it 200 (can be any number) times. I want the files to all be saved in the same directory but with numbers. Essentially creating an image sequence of one image.
Photo001.jpg
...
Photo200.jpg
Is this possible? The file reference class seems like would ask me each time where to save the file, I clearly don't want that. Ideas?
I am trying to duplicate a flex component at run time. For example if I have this:
mx: Button label="btn" id="btn" click="handleClick(event)"/>
I should be able to call a function called DuplicateComponent() and it should return me a UI component thts exactly same as above button including the event listeners with it.
I've some strange behavior using ObjectUtil.copy() and ByteArray.writeObject/readObject(). I clone an ArrayCollection and sometime the result is two identical instance of the class. Example :
[Code]...
I have created a custom even class which is pretty basic. But when calling an event and then relaying that event to another class I have encountered the "cannot transform thisEvent into thisOtherEvent" error. I realize this is because I needed to override the Clone function in my custom event like so:
[Code]...
i have a website which is basically a omegle copy (text version only) - it connects 2 random users in a chat. I hosted it on a shared hosting and also on a VPS but it "eats" the whole resources when i have 50+ users online. It "refreshes" the page every 2 seconds (its using ajax+php+mysql database). I was told, it could not be optimized any further, only delaying the refresh period. So now Iam trying to make it run many users without this problem, basically i found two options:
Make the chat using node.js+socket.io (or alternatives like APE). I dont have the knowledge and time to make this myself so I asked som freelancers about it - they can make this, but it would cost me $600 (which is too much for me ,Make it using Flash and buy a complete software from this site maybe http://www.chatroulette-clone.com - I can edit it after buying it, so I would delete the webcamera option from it. They say, that it utilizes the newest Flash technology and it should make very little server load.
I'm trying to figure out a way to clone / copy a dictionary object.
I came across some articles on cloning that offer this code.
This does not seem to work for dictionary objects. I think it only really works for basic objects.
Has anybody come across a way of cloning a dictionary before
Code:
function clone(source:Object):*
{
var myBA:ByteArray = new ByteArray();
[Code].....
I do not know how to copy a DisplayObject can anyone can help me on this one? I've downloaded an image from a website at runtime and putting it into a DisplayObject and now I'd like to create a completely separate copy of it so I do not have to make another request to download it again.
View 3 RepliesI can't work out how to create a temporary copy of a 3D point class on which I'll perform some calculations which I don't want to effect the original. In C++ it's called deep copying. How do you do it in actionscript?
[Code]...
with a "small" problem:I can't seem to duplicate or clone a mc created at runtime, with a child mc inside, which is attached at runtime... Here is my file:
View 6 Repliesi've built a little game, where the user can drag and drop objects on a canvas. there's a button wheren the canvas turns black, and the objetcs (images) become white, like a photographic image. What I'm trying to do without sucess until now, it to make the draggable objects infinit, so the user can drag as many objects as he can.
View 1 RepliesIn our app, we create complex nested movieclip with code. Essentially, we use lots of loadbytes and addchild to create these complex movieclips. Sometimes, we need to duplicate one of these complex movieclip hundreds of times to create hundreds of instances of it.Currently, we perform the "duplication" by re-creating the complex movieclips from scratch with loadbytes and such. However, this is proving to be very slow.What would be a quicker way to "duplicate" or "clone" a complex movieclip?Is there a way to serialize a complex mc into a bytearray and the resurrect it as a new object with a single loadbytes?
View 2 Replies(I see this same type of question was posted almost three years ago with no resolution, does anyone have a solution now? am trying to save a clone of a custom object (contains arrays and other custom objects as properties) to a Shared Object.Basically I have a menu system that created this program, it's running and at any point I want the user to be able to save it so he can go back to that exact point at a later date. Here is what I do so far:1. Pause the program2. The menu saves the variable that references the running program using a bytearray to a shared object3. A a later time, to load the program I pull the data from the shared object and save it to a variable, which I then treat like the original programHere is my code to save the data:
Code:
var byteArrayCloner:ByteArray = new ByteArray();
byteArrayCloner.writeObject(myProgram);
[code].....