ActionScript 3.0 :: MovieClip Sprite Versus Drawing With Graphics
Jan 26, 2012
I have a program that dynamically draws a polygon wherever the user clicks on the screen. (using lineto, moveto) However this polygon is always behind the other symbol objects on the screen even though its added last in the childlist. Is there an issue with depth when drawing symbols vs. drawing with lines? How can I ensure my dynamic object will display in front?
What more can be done if I extend MainClass with MovieClip rather than Sprite. I know that MovieClip extends Sprite and it has Timeline defined under it. But still how it will be usable to me by MovieClip ?
package { import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFormat; import flash.display.MovieClip; import flash.text.TextFieldType; [Code] ..... How to use Timeline if I replace Sprite by MovieClip ?
I'm coding games that come with the graphics done. Unfortunately the designer has some bad practices, such as not using Sprite symbols - never. And the files have dozens (even hundreds) of symbols in the library, very few of them with any animation. I would like to re-brand such symbols as Sprite to save some CPU (and maybe even kB), but my graphics-related skills are very low. Where should I start? Check and convert the symbols at authoring time or it's possible to do this at runtime? Can I effectively convert a MovieClip to Sprite (I'm guessing casting to sprite won't help much) or another light image type?
Everytime I google this question I see confusing information about masks and blends, none of which seems to directly apply to what I think should be an easy thing... There are three Sprites involved here...the lowest layer sprite is pretty much a background. I want to overlay a translucent Sprite on top of the background and then I want the third, top-most Sprite to act as a hole, so that the area inside the third Sprite is completely transparent, so that the background sprite is completely visible. How would I go about doing this dynamically (i.e. dynamically drawing the masking sprite and hole using the Actionscript graphics calls)?
I've seen the BitmapData object used for graphics a fair bit, especially in games. Many of these cases have done things in somewhat fundamentally different ways, and I was wondering what the best way generally is.
Method 1: Each animation frame is kept in a separate BitmapData object using an array.
Method 2: The animation is kept in a strip using a single BitmapData object and using the "sourceRect" parameter of copyPixels.
The draw and hitTest methods appear not to provide any "sourceRect" parameter. Most of the code I have seen using method 2 has worked around this by copying the bitmap frame into a temporary bitmap for these methods. This seems like quite a large processing overhead to me. Using method 1 this is generally not a problem, unless hitTest needs to be used with scaling and/or rotation, in which case a temporary transformed copy is still needed it seems as hitTest doesn't except a transformation.
I'm thinking method 1 is the better choice since it avoids having to make temporary copies for the most part, and I don't think it would waste much memory (just the duplicated width, height, etc values?). Is this generally true or is there a reason lots of people seem to do things the second way?
Also is there a better way to use hitTest for bitmaps that have been scaled, rotated, etc?
I have a code, that draws a horizontal line, then it turns into a slope, and at the end of the slope it draws a circle. Here's a code:
Code: var xspeed:Number = 1; // defines increments for x of slope var yspeed:Number = 2; // defines increments for y of slope var hspeed:Number = 5; // horizontal line increments
[code]....
Create document 800x700 and put this code into main timeline. Now test movie As you can see, everything works great. But there is a problem. The circle is being drawn at 0 degree angle. But I want the circle to match the angle of the slope, so it looks like the slope and the circle are both at the same angle.
I've got a custom AS3 scrollbar that I need to modify. The scroll thumb (the draggable part of a scrollbar) is currently just done by drawing a rectangle. But I need it to look more like a real scrollbar. Not sure how to modify the below code to import/use a scroll thumb image:
scrollThumb = new Sprite(); scrollThumb.graphics.lineStyle(); scrollThumb.graphics.beginFill(0x0066ff);
I am using a third party flash as3 code to load graphics using sprite. There is a class (load) that takes care of the loading of the graphics.In a new class(getname), I want to be able to1. Load the graphics (done)2. On mouseover change the color of graphics(done)3. Display name of rolled over graphic (not working). I have tried the following in getname:var feature : load;feature.name; I get a null object error. Now I have used the mousevent routine(e.target.name) and can display the instance #(instance149). But what I really want is the name of the graphics that the load function loads (graphics and the dbf with all the attributes including the name).
I"m new to AS3 and I would like to know how can I get to graphics of a Sprite so I could draw it directly from it. I mean I don"t want to use Sprite class as my concrete objects I just want Sprite to hold graphics so if my own object needs to be drawn it asks for graphics to SpriteManager which returns Sprite with required graphics and draws it exactly where I want to not where Sprite's coordinates points to.
If I have a sprite, with which I have drawn some stuff, how do I erase part of what I have drawn? Preferably I could use drawRect with some "alpha=0" paint. However, I don't believe beginFill lets you set an rgba color (like you can in bitmapdata). Setting alpha = 0 in beginFill doesn't really do anything -- it just draws nothing. In my particular use case, masking isn't an option. Also, calling clear() isn't a good solution since it clears away everything.
I have created some graphics directly in Flash Cs4 using the drawing tools, making them 'drawing objects', yet they are pixelated when viewed in browsers. Within Flash they look crisp, but not when exported.
var arrowHeadRight:Sprite = new Sprite(); with(arrowHeadRight.graphics){ beginFill(0xDDDDDD, 1); moveTo(50,0); lineTo(0,50);
[Code]...
On Mouse Over, I wish to change the color of the fill on this shape? Can this be done or do I have to re-draw the graphics with an updated beginFill line?
Is there a neat minimal way of doing this? (this produces an error):
var freeSpace = shape.freeSpace() // returns Rectangle var s:Sprite = new Sprite(); s.graphics.drawRect(freeSpace);
Just looking for a more cleaner way other than something like .drawRect(freeSpace.x, freeSpace.y, freeSpace.w, freeSpace.h) I know you can do it with bitmapData.fillRect(rectangle), but need sprites in this case.
I'm trying to understand how the Flex framework draws objects (Button, Label, Image, etc.). The Button class seems to draw itself by addChild()ing its ProgrammaticSkin. However, where in the framework is the Graphics object being passed around in the hierarchy to achieve the drawing. I want to get to the level of 2D API.
So I'm playing with a project where I want my class to be able to use the functionality of the Graphics class without needing to extend Sprite/Shape. My goal aside, I guess I'm confused as to how it works at all? It's methods don't seem to return anything, and since it's added as a child property of the Sprite/Shape classes , I can't seem to figure out what it's actually doing? It's also one of those classes that can't be instantiated.
At this point, I'm just plain curious. EDIT: I should provide more clear distinction of what I'm looking for as answer. I have read the documentation, but the documentation doesn't account for what AS3 is actually doing. I'm looking for educated guesses about the programatic relationship between Graphics and the the classes that use it.
I'm trying to debug AS3 code on production. I have no access to trace(), can't write to disk or open a socket. What I want is to display something on screen.
With AS2 I could just access _root and create a text field with my trace data.
how I can pull this off with AS3? My class extends Object, it is not a sprite and is never added to a parent display object.
I have two options and I want to know whats faster. I have a pool of 1000 sprites objects in as3 on screen. When its needed each sprite has to resize itself. I can 1- Make each sprite a simple container to use graphics to draw a rectangle, that is, call a 'spriteInstance.graphics.' ,draw the rectangle and on each 'refresh', I do graphics.clear and redraw the rectangle but with the new size, this for each sprite. or 2- Create each sprite with a border and on each refresh, resize it Whats better?
I've created a drawing tool which allows the user to draw on the canvas, the problem is that if I try to draw over a movieclip nothing happens. Is there a way I can allow for the user to draw over movieclips? For example if I had a background of paper?
Here's the code I'm using for it:
// This code is for drawing the lines on the page //1. var drawingLine:MovieClip = new MovieClip(); addChildAt(drawingLine,0);
I'm working on a game, and to keep performance good, instead of addChild'ing 50 new sprites to the stage every second, I decided to have each player draw to their own bitmap, and then to the 'master' bitmap. This introduces an issue though: the second player would override all data the first player has put into to bitmap...My basic debugging proof of concept:
I am trying to make a sprite button with graphics and can't make it work. I have successfully added text fields so I know the path is correct. I suspected my code was correct and confirmed it should be, after reading several tutorials showing the process for creating sprite buttons with graphics. Anyway, I imported nearly every class on Earth, but certainly everything which needs to be. Stage is gray and 800x600.The graphics code by itself with appear, but not when linked to the sprite. Also, the sprite won't appear no matter what. Another interesting piece of the puzzle: nothing will trace, not even objects such as textfields which actually appear and function on the stage when I text the code.
public class ContactClass extends Sprite { public function ContactClass() { var home_btn:Sprite = new Sprite();[code]....
I am working on a project in which I am suppose to maintain an array of movieclips, and I can also convert the movieclips into bitmap data. So I would like to know which one is the best to use either maintaining movieclip array or bitmap data array.
I'm working on a SmartVersioning ad using MediaMind using ActionScript 2 (the publisher doesn't allow AS3).
Skipping over how it's implemented - basically what I have is a collection of MovieClips on the main timeline that contain a swappable image (through the Smart Versioning service). You can only define objects as Smart Versioning objects if they are on the main timeline.
What I'm doing with this is using BitmapData to use the assets on the main timeline as a source for the graphics throughout the animation.
Should be as easy as:
import flash.display.BitmapData; var bmd:BitmapData = new BitmapData(143, 230, true, 0); bmd.draw(_root.person1); attachBitmap(bmd, getNextHighestDepth());