Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




OOP Adding Sprites



Its probably very straight forward but I can't seem to work it out, so maybe you guys can help! I'm making a game and in the game there is a menu screen which contains several sprites that represent the visual look of the menu.

So in MenuScrnStart.as I have proceeded to add a logo for my game like so...

private var _logo:Sprites = new Sprites;

addChildAt(_logo, 0);

'Sprites' is the class linked to my logo. This works perfectly, however, I've just gone to add another sprite and realized, if I link another sprite in my library to the Sprites class, how will flash know which sprite to put on the stage? Surely I don't have to make a different class for each individual sprite I want to add on? Can anyone assist?



ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 09-03-2008, 11:47 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

OOP Adding Sprites
Its probably very straight forward but I can't seem to work it out, so maybe you guys can help! I'm making a game and in the game there is a menu screen which contains several sprites that represent the visual look of the menu.


So in MenuScrnStart.as I have proceeded to add a logo for my game like so...


private var _logo:Sprites = new Sprites;


addChildAt(_logo, 0);


'Sprites' is the class linked to my logo. This works perfectly, however, I've just gone to add another sprite and realized, if I link another sprite in my library to the Sprites class, how will flash know which sprite to put on the stage? Surely I don't have to make a different class for each individual sprite I want to add on? Can anyone assist?

Adding Sprites To Stage In Papervision 2.0
Im trying to control a Netstream in Papervision using a scrub bar:


PHP Code:




_stream = stream;
_duration = duration;
_track = new Sprite();
_track.graphics.lineStyle();
_track.graphics.drawRect(0, -2.5, 100, 5);
addChild (_track);
_thumb = new Sprite();
_thumb.graphics.lineStyle();
_thumb.graphics.beginFill(0xFFFFFF);
_thumb.graphics.drawRect(-5, -5, 10, 10);
_thumb.graphics.endFill();
addChild(_thumb)
addEventListener(Event.ENTER_FRAME, onEnterFrame1);
_thumb.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
_thumb.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);







But how can I add Sprites to the stage in Papervision?

Adding Bitmaps To Sprites, Not Showing (pv3d)
Hi,

I am not sure if this is an actionscript or a Papervision issue that I have, so I thought I post it here too. I am adding bitmaps to sprites in a loop, but they only are being shown partly (not all of them) and randomly). If I add them one by one, outside the loop, they are shown correctly (but there 180 of them, so I don't want to do it that way).



Code:
private function createMaterial():void{

for( var m:uint=0; m< numOfPlanes; m++){


material[m] = new MovieAssetMaterial("MatAsset",true,true,true);
material[m].name="mat"+ m;
material[m].smooth = true;
material[m].oneSide = true;
material[m].opposite = true;
material[m].interactive = true;
Sprite(material[m].movie).cacheAsBitmap=true;
Sprite(material[m].movie).alpha=ALPHA_OUT;
//this only shows part of the bitmaps, randomly:
//Sprite(material[m].movie).addChild(Bitmap(picArray[m]));

//trace("Sprite(material["+ m+ "].movie).getChildAt(1) ="+ Sprite(material[m].movie).getChildAt(1));//traces 180 times [object Bitmap]
}
//this works:
Sprite(material[0].movie).addChild(Bitmap(picArray[0]));
Sprite(material[1].movie).addChild(Bitmap(picArray[1]));
Sprite(material[2].movie).addChild(Bitmap(picArray[2]));
Sprite(material[3].movie).addChild(Bitmap(picArray[3]));
Sprite(material[4].movie).addChild(Bitmap(picArray[4]));
Sprite(material[5].movie).addChild(Bitmap(picArray[5]));
}
I really don't know what is going wrong, so any help would be highly appreciated,

thanks,

Jerryj/

Adding Bitmaps To Sprites But Only Showing Partly (pv3d)
Hi,

I am not sure if this is an actionscript or a Papervision issue that I have, so I thought I post it here too. I am adding bitmaps to sprites in a loop, but they only are being shown partly (not all of them) and randomly). If I add them one by one, outside the loop, they are shown correctly (but there 180 of them, so I don't want to do it that way).



Code:
private function createMaterial():void{

for( var m:uint=0; m< numOfPlanes; m++){


material[m] = new MovieAssetMaterial("MatAsset",true,true,true);
material[m].name="mat"+ m;
material[m].smooth = true;
material[m].oneSide = true;
material[m].opposite = true;
material[m].interactive = true;
Sprite(material[m].movie).cacheAsBitmap=true;
Sprite(material[m].movie).alpha=ALPHA_OUT;
//this only shows part of the bitmaps, randomly:
//Sprite(material[m].movie).addChild(Bitmap(picArray[m]));

//trace("Sprite(material["+ m+ "].movie).getChildAt(1) ="+ Sprite(material[m].movie).getChildAt(1));//traces 180 times [object Bitmap]
}
//this works:
Sprite(material[0].movie).addChild(Bitmap(picArray[0]));
Sprite(material[1].movie).addChild(Bitmap(picArray[1]));
Sprite(material[2].movie).addChild(Bitmap(picArray[2]));
Sprite(material[3].movie).addChild(Bitmap(picArray[3]));
Sprite(material[4].movie).addChild(Bitmap(picArray[4]));
Sprite(material[5].movie).addChild(Bitmap(picArray[5]));
}


I really don't know what is going wrong, so any help would be highly appreciated,

thanks,

Jerryj/

Stupid DisplayList Problem: Sprites Added To Sprites Appear As "not Found..."
I'm creating an unholy mess of sprites because I clearly hate myself. With that out of the way, here's what I'm running into.

I've created a class that in turn generates a bunch of sprites for itself. This all works as it should. However, I'm trying to put some of those sprites on other sprites within the class, like this:



Code:
classInstance=this; // extends Sprite
sprite1=new Sprite();
sprite2=new Sprite();

sprite1.addChild(sprite2);
classInstance.addChild(sprite1);

trace (classInstance.sprite1.contains(sprite2)); // returns true

trace (classInstance.sprite1.sprite2); // returns "Reference error: Error #1069: Property sprite2 not found on flash.display.Sprite and there is no default value.
It seems as though Flash doesn't give a rip that sprite2 is a Sprite which happens to be a child of sprite1 which happens to be a child of classInstance...

What am I doing wrong? (All of this stuff is declared in the class: I left it out for clarity, but I'm happy to post more craptastic code if necessary). Thanks in advance for any help!

Adding "Sprites" Or "movieClips"
How do i add sprites.. er... movieClips... into macromedia flash 8? Im not sure how you would do that so is there a place i can find a tutorial for that stuff?

Dbz Sprites
anyone know where i can get abunch of dbz sprites or have multiple webistes with dbz sprites?

thanks

Help With Sprites
I've been using swish for about four years now, and I've gotten pretty good at using it, but I've come to find that I need help with this problem with my sprite...

I making a cartoon war scene, and I was thought it would be easier to put all the actions of a gun (reload, fire, and cock) in one sprite and seperate each of these actions with a stop action. I also put a label at the beginning of each action, so basicly I have a short sprite that (without stop actions) would first reload, fire, and cock in a span of about 30 frames. Now what I want to do is be able to trigger one of these actions from the main timeline. For example one of the guys in my movie will be firing one of the guns, so each time I want him to fire I want to be able to put in an action that says something like "goto fire of shotgun sprite".

I'm not sure how easy this is going to be to understand from others' point of views. But that's as clear as I can explain it.

I would really appreiciate any help.

Using Sprites I Need Some Help
is there a quick way of puting sprites from a sprite sheet into your animation?

ive tried puting individual sprites into the library from files i made (3 of them each with a walk pose on it) but there seems to be a white square around the sprite so it does not work for me

is there an eaiser way to do it?

Sprites?
I'm new to flash. I have used swish for years. I've lost most of my hair trying to learn flash. If anyone has used swish and could tell me the flash equiv. of a swish sprite I would ver appreciative.

I would like to to create a symbol and assign it a transition, then on the main timeline be able to move and manipulate the symbol all the while the symbol is looping it's previously defined transition.

Thanks, Jeremy

Sprites...
Hi evrybody...
I have a problem how do i set sprites like super mario in a flash movie...

Sprites
When I paste a picture on the workspace, it has a white background that I can't get rid of. Somebody please tell me how to get rid of that freggin' white background! (Using Flash MX)

Help Me With Sprites
How do you make it so the sprite goes directly over the other one, i cant get them to line up directly even with onion skin on, and so they move choppy. Can anyone tell me how to get them to line up so they dont move choppy?

Sprites
How do you remove the white thing around your sprites?

Sprites
I am making a movie with mario sprites. what i did was i saved a picture of a sprite sheet, put it on paint, and took only single mario characters to animate off the sheet. but whenever i put them on flash and i put a picture in the background, you can see a white square around them, which messed up the backgorund. i cannot get rid of the white square!! any ideas?

thanks

P.S. Im using flash 8.

Using Sprites
i finally got a basic (soon to be) rpg game going, but i want it to be a bit better by making a more realistic character. so i drew one with legs and arms and all, does anyone know how i can apply the different sprites i drew in flash.

ex. so when i press right, it uses the sprites for moving right.

[F8] Map And Sprites
hi!

I'm making a game where you have a top view of a map and you can move your character through it. But my map is highly irregular shape. Is there an efficient way to restrict movement of a sprite, so that it won't go beyond the borders of the map?? I'm pretty clueless here, so any approaches are appreciated

[CS3/AS2] Sprites X(
I am just in the middle of working with sprites and such and I have a huge problem. When you import sprites there is the grey box that goes around when you select, and then I trace bitmap but when I do that the sprite gets all blurry and doesn't look like sprite anymore I have changed and messed with all the settings and still does it. I have tried all settings on the trace bitmap so please don't give me anymore. I just want my sprites to look like sprites and no blur or anything. Hope someone knows a solution, thanks!

Sprites.
I have recently started scripting in flash and have come across the word "sprite" what is that exactly and how does it work bcoz ive seen the same term in other applications like flex and platform.

Snezaa.

Sprites
Whats a good way to put sprites into flash? Everytime i input a sprite into flash it comes up with a white border around it.

Sprites And Such
Hey,
I need help with something. I dont think im making sprite movies entirely correctly. Im just importing the pictures and using them. But they have the backround that doesnt match the movies backround. So i need to know how to make it so the sprites backround doesnt even show. I attached a small example.

Sprites
Whats a good way to put sprites into flash? Everytime i input a sprite into flash it comes up with a white border around it.

Sprites And Such
Hey,
I need help with something. I dont think im making sprite movies entirely correctly. Im just importing the pictures and using them. But they have the backround that doesnt match the movies backround. So i need to know how to make it so the sprites backround doesnt even show. I attached a small example.

Sprites Help
I need to know how to make a sprite move one way when a button is pressed and stay that way, for example: when i press left I want my walk left sprite to move left, then when you take your finger off the left button, it will stop and show the stand facing left sprite, same with the right.

this is what I've got,

Code:


// Press "Right" to move Player left.
if(key.isDown(key.right)) {
_root.tochu._x += speed;
_root.tochu.gotoAndPlay(9);
}

// Press "Left" to move Player right.
else if(key.isDown(key.left)) {
_root.tochu._x -= speed;
}
...

Moving Sprites
Im seeking to make a click and drag components thing for my web page wehre i can click and drag brain bubbles and cyborg arms across onto a normal looking person to make them end up rather like a cyborg. The script for this will be almost identical to dres up programs like those wehre yo uget to click and drag outfit's onto santa and make him look funny. i can make the pictures just find but i dont know how to make the components moveable. I want this information by tomorrow so a speedy response is ideal. Thanx for reading wether you can help me or not.

Sprites In Flash
hey i have some questions about using video game sprites in flash. please anwser as many as can if possiable.

1. when using sprites in flash, is it best to just use frame by frame or incorperate some tweening to make some processes easier.

2. a friend of mine said that in flash if you use sprites that it is like makeing a .gif only longer and with sound.

3. can you use the flash tools to edut the sprite like make more blood if its Mortal Kombat or edit things on the charater.

4. sould i use sptite sheet or my own ripped spirtes if that is possiable to do. or can i use animated .gif in the movie.

thank you, if you can help me with any of these qusetions

Getting Sprites Into Flash
hi, i have trouble with getting sprites in to flash.

here are my main problems.

1. every time i cut out the sprite there all ways, some stuff i didn't cut off. i see these flash movies with sprites, and there so perfectly cut out i start to think that they didn't cut them out like had to.

http://www.newgrounds.com/portal/view.php?id=12376

2.my windows program won't let me edit .gif type files so i have to put it in .jpg were it loses quality.

is there any secret to flsh sprites, or am i missing skill that will aid me it this pursuit.

Thank you,

Question About Sprites
Ok i want to open a display a webpage inside of a sprite. is that possible?

Animating Sprites.
I have two sprites that I want to join together into one single animation. The two sprites when put together would make the character run. After I do that I just want to use a simple motion tween to make the animation move accross the screen. Other than the motion tween, how do I join the sprites together?

Any help would be great,

Thanks,

Ripping Sprites
I am currently working on an animation involving video game sprites. I was wondering if anyone here new how to rip them from roms with out printing the screen and editing in flash. Is there a way to hack in and get them via the game engine. I am currently using zsnes. This is a little off of the topic of Flash however I figured that someone here would know because sprite rips and Flash animation go hand in hand. Thanks

Add Sprites In Flash 5
Sorry about first previuce post It Was wrong Subject really sorry please.

hi,
respected sir,

I'm user of swish but very new to flash.so i want to know that can we add sprites in flash 5 if yes please tell me how is there any tutorial about this ?
can we add swf files as like we add in swish and .gifs ??
thanks

A-Ghani

Delaying Sprites
Hi I have made 15 buttons that I want to enter at a delayed time on the page enter. I have music that plays when you open the page and when the buttons enter they also play music. I want the(page enter) music to stop playing and then the buttons come in. I dont want to much music all at once that clashes. Is there an easy way to delay my buttons about 10 seconds on arrival, without having to add more frames to the sprites? I have 15 buttons that i want to come in about .5 seconds apart from each other. If i have to many frames per sprite it will take a long time to load being 15 buttons. How do i do this without making the file size huge? Thanks

Clueless

Sprites In Flash
if i use sprites in flash (characters from old 2d games) is there a way to have flash NOT smooth out the image. i want to maintain the old style, crisp pixelated effect. i've seen it done, but how i can do it?

Moving Sprites
hello i has a question regarding video game sprites
how to u get the animated ones i.e sonic/mario running to run in a direction without moving each individual frame of them

Flash Sprites
I am trying to create a rpg in flash 8 and I am trying to use rpg maker sprites for the sprites. So far I am having problems in getting the sprites to move correctly is there any tutorials that go into making,moving,and animating the sprites?

Help With Building Sprites
Hi. I'm really new to Flash and a bit crap at it and I'm trying to make a twoplayer breakout game and I'm having trouble with getting the bricks built when the game starts. It seems like a bit of a cop out to place them all manually.
What I want it a set of bricks 10 x 4 at the top and the bottom of the screen.
Does anyone have any idea how to do this?
Thanks a million.

Movement With Sprites
I have a series of sprites (a man walking, jumping, facing forward) and I want to put them into a movie clip so when I hit the space bar, the man jumps, when I hit the left/right arrow he walks accordingly, and when I hit the down arrow he faces the screen. Like I already said I have the sprites made up I just need help with the action script. Also where do I put the script? Do I have to make a new layer and call it actions?

Thanks

Erik

Sprites In The Library
I typically have a bunch of MovieClip assets in my library. Now with AS3, it would be a better practice for most of them to Sprites instead of MovieClips. The only way I can do this is to "Export for Actionscript" and make the base class flash.display.Sprite.

I want to use Sprites to decrease overhead, but it seems that by creating another MC that has to be exported for as at runtime, it is a catch22.

Does anyone know what best practice is for this, or have any advice?

Thanks!

Animating Sprites
I have a sprite sheet, but i can't even figure out how to take a single sprite from it and make it its own layer...Sad that i'm stuck this early in lol. but any help is appreciated

Tracing Sprites
Hi,

I´m trying to make some short sprite movies and have some quick questions.
When I select the desired sprites and start tracing them, which options should I pick?

Color threshold: 1
Minimum area: 1
Curve fit: Pixels
Coner threshold: Many Corners

or

Color threshold: 100
Minimum area: 1
Curve fit: Pixels
Coner threshold: Normal

I applied both ways to my NES Super Mario Bros sprite and the result was the same, however the 3-frames sprite is very basic.

How do those changes affect the more complex sprites with hundreds of colors?

Thanks.

[CS3] Sprites Or Movieclips?
Hi,

I'm trying to develop an application which displays to the user a graphic of a keyboard. When they click each individual key the letter is displayed in a box below.

My question is, is it better that I have a movieclip for each key, or load in an image of a keyboard and somehow divide it up dynamically? I've read about using sprites and stuff for animation but I don't know if this is the best way to go about it.

Any advice appreciated,

Crung.

[cs3] Hit Testing Two Sprites
Greetings folks!

I'm reading Foundation Actionscript 3.0 Animation: Making Things Move and I'm stuck on this little program. I looked for an errata, but didn't found it.


Code:
package
{
import flash.display.Sprite;
import flash.events.Event;
public class ObjectHitTest extends Sprite
{
private var ball1:Ball;
private var ball2:Ball;
public function ObjectHitTest()
{
init();
}
private function init():void
{
ball1 = new Ball();
addChild(ball1);
ball1.x = stage.stageWidth / 2;
ball1.y = stage.stageHeight / 2;
ball2 = new Ball();
addChild(ball2);
ball2.startDrag(true);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void
{
if(ball1.hitTestObject(ball2))
{
trace("hit");
}
}
}
}
I get the following errors:

Code:
Line 7 - 1046: Type was not found or was not a compile-time constant: Ball.
Line 8 - 1046: Type was not found or was not a compile-time constant: Ball.
Line 15 - 1180: Call to a possibly undefined method Ball.
Line 19 - 1180: Call to a possibly undefined method Ball.
I have created two balls on the .fla file, ball1 and ball2.

If someone read this book, does it have lots of errors? Because if so, it's a pain for an actionscript beginner (like me) and I might look for another book.

Thanks.

Sprites And Perspective
I've seen a lot of perspective effects that use bitmaps, usually by cutting them into triangles and then respectively skewing each slice...

Does anyone know of a way to achieve a similar effect with a sprite or movieclip? Specifically, I have some vector art that I would prefer to use instead of bitmaps in order to maintain quality (even if it costs performance).

The art in this instance is done by hand, not scripted, otherwise I would use some 3D math equations.

Anyway, let me know if you have any ideas. Thanks!

LocalToGlobal With Sprites?
I'm trying to track where a sprite is on the stage, but I can't seem to coax out its global coordinates. Anything I do gives me (0,0), regardless of how I move it around. I've tried localToGlobal with Points but keep getting errors. How can I get the global coordinates of a sprite?

Help With Animating Sprites.
Hi, I am having problems with animating my sprites. I keep getting a light blue background when I use them and can't quite seem to get rid of it. Is there a way I can make it transparent? I'm a noob at this flash stuff... I provided a screen shot about that I am talking about. Please look at it, It's the light blue background around edward. I just started making this flash video and would like some help. Thanks!

Resizing Sprites
Hello all,

I have a sprite containing 2 sprites, one on the left side and one on the right and then there's some space in between. Now, these two sprites on the sides are handles that when dragged should modify the width of the parent sprite.

The problem is when I set the width of the parent the handles contained within are scaled down. Anyone know how to change the width of a sprite without affecting the children?

Edit: The handles where 27 pixels wide at the begning and should stay that way. I tried setting them back to 27 pixels manually after a resize of the parent but that didnt help. :s

Edit2: With html this would be done by having a div with two divs in it and then just resize the parent div, the sub-divs would stay attached to the sides and remaining in size.

Targeting Sprites?
Hi All
I am working on a little class in which I have a image that is loaded into a sprite. this works fine. I also create a sprite that acts as a button. I have a on click listener on the button sprite. that works. but what I need is to be able to target the sibling that has the image so I can scale it on press. In as2 I would simply do this._parent.imgHolderMc from the press function. but that does not work or anything like that.


Code:
package {
import flash.display.*;
import flash.events.*;
import flash.net.URLRequest;
import flash.geom.Rectangle
public class zoomer extends Sprite {
function zoomer () {
loadImage ("assets/images/2.jpg");
}
public function loadImage (u:String) {
var _loader:Loader = new Loader();
_loader.contentLoaderInfo.addEventListener (Event.COMPLETE,onComplete);
var request:URLRequest = new URLRequest(u);
var loaderHolder:Sprite = new Sprite();
addChild ( loaderHolder );
_loader.load (request);
loaderHolder.addChild (_loader);
var square:Sprite = new Sprite();
square.graphics.beginFill (0xFF);
square.graphics.drawRoundRect (0, 0, 200, 200, 10, 10);
square.graphics.endFill ();
addChild (square);
loaderHolder.mask=square;
loaderHolder.addEventListener (MouseEvent.MOUSE_DOWN, mouseDown);
function mouseDown (event:MouseEvent):void {
var myRectangle:Rectangle=new Rectangle(-100,-100,100,100);
loaderHolder.startDrag (false,myRectangle);
//loaderHolder.startDrag (false);
}
loaderHolder.addEventListener (MouseEvent.MOUSE_UP, mouseReleased);
function mouseReleased (event:MouseEvent):void {
loaderHolder.stopDrag ();
trace (loaderHolder.dropTarget.name);
}
buildBtn ();
}
function buildBtn () {
var square:Sprite = new Sprite();
square.graphics.beginFill (0xFF);
square.graphics.drawRoundRect (0, 0, 20, 20, 10, 10);
square.graphics.endFill ();
addChild (square);
square.addEventListener (MouseEvent.MOUSE_DOWN, zBtnDown);

}
public var zTogle:Boolean = false;
private function zBtnDown (event:MouseEvent):void {
var sprite:Sprite = Sprite(event.target);
trace (zTogle);
if (!zTogle) {
sprite.scaleX=.5;
sprite.scaleY=.5;
zTogle=true;
} else {
sprite.scaleX=1;
sprite.scaleY=1;
zTogle=false;
}
}
public function onComplete (ev:Event):void {
}
}
}
so what I need is the loaderHolder to be scaled when the zBtnDown sprite is pressed.

any help would be great

How To Use Sprites In Animation.
Umm hi I would like some help on how to use sprites (8 or 16 bit characters from games) to make an animation could any one provide me a link to any sprites animation or a link on how to do it. It will help much.

Mr.Idiot

Sprites Or Blitting
I have just started using Actionscript 3 and some of the features that were in 8 - mainly the bitmap data functions. But I am curious about best practices.

My understanding was that Flash player 8 made use of OpenGL where it could - so am I going to cripple my game's performance if I use the bitmap functions to 'blit' images around instead of using Sprites? Or does the player use OpenGl to render the images I move around with the Bitmap copy and merge functions?

I have attached a FPS counter to a test movie and it seems okay but I would like other's opinions before totally comitting to that route.

Copyright © 2005-08 www.BigResource.com, All rights reserved