sum of the sprites in sprite
Newbie here. Writing a Manager to add the number of sprites to a cast member located within the boundaries of another sprite. Thank you.
I would do it with a kind of system of legend. There is a global variable, we'll call it gTotal, which stores the actual number of sprites in one another. Make a #movie like this script:
global gTotal
on getNumWithin vSpriteNum
Direct = .rect sprite (vSpriteNum)
gTotal = 0
sendAllSprites (#AreYouWithin, iRect)
end
Then put behavior on sprites which are mobile (i.e. those that could be within the other sprite)
global gTotal
on AreYouWithin me, vRect
If sprite (me.spriteNum).rect.union (vRect) = vRect then
gTotal = gTotal + 1
end if
end
Now, all you need to do is use the command:
getNumWithin (spriteNameOrNum)
and check the value of gTotal. So basically, if you check to see how many sprites are within the limits of the sprite in channel 10, you would call:
getNumWithin (10)
put gTotal
and gTotal would have the correct number of sprites. If you name your sprites (Director 10 and above), you can use the name of the sprite instead of the number of the sprite.
Tags: Director
Similar Questions
-
The label on the top of the Sprite event management
Hi everyone, it's more of a general question of Actionscript, but Google does offer all the answers.
So I made a custom component, element that extends the Sprite class. I draw things on the graphics in this class and then I add a Label to display text.
In another class, where I create instances of the previous class, I add an EventListener for MouseEvent.Click. In this function, there is this line:
selectedElement = Element(event.target);
In short, I want the variable selectedElement to contain the element on which click it. But I ran into problems, event.target is not always an instance of my class. If I click where the label is, event.target is a Label.
How can I organize if click anywhere on my element, in particular on the label, it's the element of class that dispatches an event and not on its label. I think I need to intercept events of labels in some way, but no idea how to do this.
Thank you in advance.
Too bad, in the event class stopPropagation method has been what I was looking for.
-
Wait for the sprite press / clicked
Hi, I am trying to display graphics when the user touches the sprite first which I reproduce, then another graphic when the user releases the sprite (raises their finger). I don't know how to go on this subject! Please help me!
Thanks in advance
On the Sprite that you draw in, add an event listener for mouse down and mouse upwards. This will work only on drawn graphs and not areas of the sprite which pulled anything in.
private var sprite: Sprite = new Sprite();
//...
addChild (sprite);
make the drawing
sprite.addEventListener (MouseEvent.MOUSE_DOWN, MouseDown);
//...
private function MouseDown (event: MouseEvent): void
{
this.sprite.addEventListener (MouseEvent.MOUSE_UP, MouseUp);
do something
}
private void MouseUp (event: MouseEvent): void
{
this.sprite.removeEventListener (MouseEvent.MOUSE_UP, MouseUp);
do something
}
-
reset the position of the sprites
Hello world
I'm unable to a simple matching game.
Basically, I want to create a code that will ensure that each sprite is at a location given at the beginning of each game. Currently these sprites are not in their correct location when the game is re-played.
The following code displays the error "Script error: property not found. Can someone tell me what is wrong with him?
on prepareFrame me
-put the sprites where they are supposed to be
resetpOrigLoc()
end
on resetpOrigLoc
Member("Kngwarria").loc = point (73, 111)
Member("Kamaarra").loc = point (151, 69)
Member("Ngala").loc = point (220,24)
Member("Pungarta").loc = point (307,68)
Member("Pilthaarra").loc = point (375,25)
Member("Purrula").loc = point (445,68)
Member("Mpitjaana").loc = point (549,112)
end
Thank you, else
As James suggested:
However, you call this Manager each time Manager refreshes the screen, so the sprites will be constantly placed in these positions, even if the user tries to move them.
I suspect that you want 'resetpOrigLoc()' Manager in a beginSprite handler, instead of prepareFrame.
-
Actions on the sprite sheet are ignored!
Hello
Super weird, I imported sprite sheet (with Flash) and all the actions on stage or inside the sprite sheet symbol are ignored, while other animations play.
Like reverse playback...
Help, please!
To create say an effect loop for the symbol of sprite sheet, you need to bindTimelineAction for the sprite sheet symbol.
Symbol.bindTimelineAction (compId, 'bird', 'Default editing', 'complete', function (sym, e) {})
SYM. Play (0);
});
Here the birds is the name of the sprite sheet symbol and the above code is added to the event of 'compositionReady' of the stadium.
I enclose a sample of reference.
Thank you and best regards,
Roger Simon
-
The code I have so far.
The sprite is equal to a paddle which I want to go left to right on the screen using the arrow keys.
However, the code allows only the palette in the direction of the + code, I assumed - would do the opposite, but he stops just the sprite to move.
Also I have this code in on prepareFrame me, did had no effect on the code?
If keycode = 124 then - right arrow key
Sprite (27) .locH = sprite (27) .locH - 2
on the other
If .loc sprite (27) = (477) then - this code was to stop the paddle loose at the edge of the screen.
If keycode = 123
Sprite (27) .locH = .locH sprite (27) + 2
end if
end if
end if
end
any help with this would be greatly appreciated thanks.
This is a behavior that you can attach to your sprite who does what you want.
Min and Max of locH values are precalculated in beginSprite. It is slightly more efficient and makes the EnterFrame code easier to understand.
-Movement of Sprite with the behavior of the keys left/right arrow
Sp property - refers to this sprite
property speed - the number of pixels to move the sprite each image
property MaxRight - locH Maximum sprite can move to
MinLeft property - locH Minimum sprite can move to
On GetBehaviorDescription me
return ' movement left/right Sprite with arrows. "
end GetBehaviorDescription
On GetPropertyDescriptionList me
Accessories = [:]
Accessories [#Speed] = [#default: 5, #format: #integer, #Range: [#min:1, #max: 20], #comment: "Number of pixels to move sprite every EnterFrame."]
return accessories
end GetPropertyDescriptionList
on beginSprite me
SP = sprite (me.spriteNum)
-calculate MaxRight, MinLeft
regPoint = Sp.member.regpoint
MinLeft = regPoint [1]
MaxRight (stage) =.rect.width - (Sp.width - regPoint [1])
end beginSprite
on enterFrame me
If _key.keyPressed (123) then - left arrow
Sp.locH = max (Sp.locH - speed, MinLeft)
end if
If _key.keyPressed (124) so - right arrow
Sp.locH = min (Sp.locH + speed, MaxRight)
end if
end enterFrame
-
How to get the number of the sprite in a KeyUp script?
I have an application with a series of text entry fields. Users enter numeric values in each field. I want to have the keyboard focus to the next field when the user clicks on the Enter key. So far I've been able to do this by hard coding the following sprite as follows number...
-----
box (_Key.keycode) of
36:-Enter key
_movie.keyboardFocusSprite = 64 - this is the value hardcoded the following sprite
numString = member("ALA_CFTHolder").text
otherwise:-manages the regular entries
...
cases of termination
-----
I want to find a way to move to the next sprite without hard-code the value. I tried to read the _movie.keyboardFocusSprite but he is always-1. There must be a way to do this.
Thank you.
See if this code will help you. Any sprite channel, the fields are in, but the focus order is determined by the order in which the sprites appear on the partition. If this isn't what you want, it will take a different approach.
---------------------------------------------------------------------
property spriteNum, pEntrySpriteList
on beginSprite me
pEntrySpriteList =]
sendAllSprites (#updateEntrySpriteList, spriteNum)
end
on updateEntrySpriteList me, senderSpriteNum
pEntrySpriteList.add (senderSpriteNum)
If spriteNum <> senderSpriteNum then (senderSpriteNum) sprite (spriteNum).pEntrySpriteList.add
end
on keyDown me
case (keycode)
36:-Enter key
myIndex = pEntrySpriteList.findPos (spriteNum)
If myIndex = pEntrySpriteList.count then
the keyboardFocusSprite = pEntrySpriteList [1]
on the other
the keyboardFocusSprite = pEntrySpriteList [myIndex + 1]
end if
otherwise:-manages the regular entries
Pass
cases of termination
end
-
How to return the sprite object?
I want to load both image and add each image to each sprite object, like photo one sprite1 and photo b to spriteb, I know that I can load a pictue with the following code:
loadImage ('a');
loadImage ('b');
private void loadImage(imagePath:String):void {}
var loader: Loader = new Loader();
loader.contentLoaderInfo.addEventListener (Event.COMPLETE, onImageLoaded);
Loader.Load (new URLRequest (imagePath));
}
private void onImageLoaded(event:Event):Sprite {}
var loaderInfo:LoaderInfo = event.target as LoaderInfo;
_loadedBitmap = LoaderInfo.Content as Bitmap;
Return runPostImageLoad (_sprite);
}
private void runPostImageLoad(_sprite:Sprite):Sprite {}
... photo of //load
}But I want to make my code like the following, because I want to use sprite1, sprite2 for something else:
var sprite1:Sprite = loadImage ('a');
var sprite2:Sprite = loadImage ('b');I don't know how to change the loadImage function to return the sprite object. Could someone tell me how to do?
Thank you
use:
private var _sprite:Sprite;
.
.
private void loadImage(imagePath:String):Sprite {}
var loader: Loader = new Loader();
Loader.Name = "Loader";
loader.contentLoaderInfo.addEventListener (Event.COMPLETE, onImageLoaded);
Loader.Load (new URLRequest (imagePath));
_sprite = new Sprite();
_sprite. AddChild ("Loader");
return _sprite
}
private void onImageLoaded(event:Event):void {}
var loaderInfo:LoaderInfo = event.target as LoaderInfo;
_loadedBitmap = LoaderInfo.Content as Bitmap;
runPostImageLoad();
}
private function runPostImageLoad (): void {}
just draw the shape of the irregular part
If (_loadedBitmap...) {
_sprite.removeChild (_sprite.getChildByName ("loader"));
_sprite. Graphics.drawRect (...);
}
}
p.s. Please check the correct and useful.
-
Objects added to the Sprite/MC are not
Hello everyone, I worked on a construction set and met a strange problem this morning, when instead of adding objects directly to the step that I had to add a Sprite (I also tried with a MovieClip) on the stage instead and they do not seem to. If anyone can see why this is happening, I will be eternally grateful, because it has left me speechless! And Yes, before anyone says, the MC/Sprite I add objects to a certainly added to the stage, I've made this mistake before and do not rely on what actually once again
I essentially built the game levels using various different objects (rectangles, circles, etc.), built in the attached with sprites and Box2D physics engine to represent the user. During the creation of each of these object I provide a DisplayObjectContainer in which the sprite that represents the object should be placed. So far I've been simply supply my class of basic game as DisplayObjectContainer, with no problems whatsoever - everything is displayed properly. A new level design, however, it will take apply me a mask to the level (but not the GUI) so I decided to put all the objects level within a MovieClip or Sprite instead. I created the new sprite as such:
levelObjects = new Sprite();
levelObjects.x = levelObjects.y = 0; In order to ensure
levelObjects.width = GameProperties.stageWidth;
levelObjects.height = GameProperties.stageHeight;
levelObjects.visible = true; In order to ensure
addChild (levelObjects)and have provided this sprite for level objects like a DisplayObjectContainer instead of the base class. Everything is added to the stage that I can click on things and sounds associated with the objects game play correctly, but nothing is actually visible! As I mentioned above, I tried this using a MovieClip instead but got the same result. Anyone has an idea why this is happening and how I can fix this problem? Thank you for posting anything that might help, I have tried everything I can think so now I'm going to rack your brain rather haha
Thanks in advance,
Dinkyfish
Cannot set the width and height of an empty object properties... I mean you can, but it will not work and curiously has an effect of making things do not appear.
-
Confused about the extension of the Sprite class
Howdy-
I learn programming with object oriented ActionScript and am confused about the class Sprite and OO in general.
My understanding is that the Sprite class allows you to group a set of objects that you can manipulate all the objects at the same time.
I explored the Open Flash Chart code and note that the main class extends the Sprite class:
Base/public class extends Sprite {}
What this lets you do?
Also, on a related note, how to draw, say, a line once I extended?
Without extend Sprite I could write:
var graphContainer:Sprite = new Sprite();
var newLine:Graphics = graphContainer.graphics;
...
And it works very well. Once I have extend the Sprite class, I'm lost. How can I modify this code so that it still draws a line? I tried:
var newLine:Graphics = this.graphics;
My understanding is that since I extend the Sprite class, I should still be able to call its method chart (or property? I have no idea). But, he screams at me, saying "1046: Type was not found or is not a constant of compilation: graphs.»
A number of things.
First of all, I would not use this approach in your table constructor. Setting the width and height only makes sense if you adjust the width and height of the existing content, and the table (Sprite) does not at this time here. If you want to give the table a 'size', you could do it like this:
public function Chart (width: Number, height: Number) {}
This.Width = width;
This.Height = height;
put in a background invisible to this size:
this.graphics.beginFill (0,0);
this.graphics.drawRect (0,0,width,height);
}There are other ways, including putting in a form or a Sprite of child as a child for the background so that clear will not erase the background of the chart. This way you could have properties for the background in your table class and update the background as a child DisplayObject instance... a few ideas to think to...
Then, after that, your chart should be functional...
Then back in your scenario, you could do this:
import graphics. Table;
Stop()
var myNewChart:Chart = new Chart (300,200)
myNewChart.render ();
addChild (myNewChart) -
Hi, I have problems with having my bytearray (which is an image) in a sprite. This is my attempt to date:
var imgB:BitmapData = new BitmapData(271, 278, true, 0xff0000); imgB.setPixels(new Rectangle(0,0,271,278), $imgData); $image.graphics.beginBitmapFill(imgB,new Matrix(), false, true);
My byteArray is $imgData and the sprite I want to draw $image. When I run the above code I get EOF error:
Error: Error #2030: End of file was encountered. at flash.display::BitmapData/setPixels()
Any thoughts? Thank you
I'm not sure of what you're trying to do here... but you can not use the binary data that you loaded with a URLLoader as bitmapData, if she was responsible for a png or jpeg for example. These file formats must be decoded in bitmapData - using the native support for this drive seems preferable.
He does not seem to be a delay of frame with the loadBytes method and you cannot intercept using the FULL event, as you say.
I got it works like this (maybe there is a better way than using the enterFrame, but I just did this quickly to check)
var $image:Sprite=new Sprite(); addChild($image); var myBitmapData:BitmapData; var imageLoader:Loader = new Loader() var dataLoader:URLLoader=new URLLoader(); dataLoader.dataFormat = flash.net.URLLoaderDataFormat.BINARY dataLoader.addEventListener(Event.COMPLETE,completeHandler) function loadImage(url:String):void{ var req:URLRequest=new URLRequest(url); dataLoader.load(req) } function completeHandler(e:Event):void{ //use enterFrame to check for loaded content imageLoader.addEventListener(Event.ENTER_FRAME,imageDecodeHandler); imageLoader.loadBytes(e.currentTarget.data); } function imageDecodeHandler(e:Event):void{ if (imageLoader.content) { trace('loaded') imageLoader.removeEventListener(Event.ENTER_FRAME,imageDecodeHandler); myBitmapData = Bitmap(imageLoader.content).bitmapData; //imageLoader.content width and height available now as well as myBitmapdata.rect etc $image.graphics.beginBitmapFill(myBitmapData,null,true,true); $image.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight); $image.graphics.endFill() } else { trace('not yet loaded') } } //substitute a local image file here: loadImage("46.png")
-
Hello everyone, would you please show me a way to put a sprite from another sprite on the stage (for example the sprite a resident 5 mm to the b on the stage, when a, b of sprite sprite does not change compared to the sprite sprite one)? (could you please introduce me a tutorial or a sample abut this case)
Sincerely yours MohsenaTry something like:
-attached to the sprite b:
on beginSprite me
Sprite (me.spriteNum) .loc = .loc sprite (a) + point (5, 0)
end -
I have a script on a chart with an arrow down. When I click on the button, I want to spend anoter sprite named "letter". The script works, but the repeat loop to continue the sprite while the mouse button is released - actis instantly. So instead of slowly, move 5 pixels at a time, he moves to 200 pixels at a time (this range is defined in the script, since the start position of the sprite is 495 - 495-295 = 200).
Can someone let me know if there is a code I can insert in the repeat loop to slow it down?
JARGON CODE IS ATTACHED.
Thanks for all the help again. I finally got it!
-
Problem changing what the sprite size?
I want to adjust the size of the sprite, some changing their attributes of LOW TOP, LEFT, RIGHT. For example, I want to use this code to create a longer box shape:
Sprite (1) .the = sprite (1) .the - 5
Sprite (1) .right = .right sprite (1) + 5
In my mind, the left edge of box (sprite (1)) should pass to the left for 5 unit and right edge move right 5 unit. But in fact, only the right move. The left does not move!
See my example:
http://www.gzvr.com/test/ChangeSpriteEdge.htm
If all the LEFT RIGHT UP DOWN are defined in the code as above, I found that the last line of code works! Why?
Try this:
vSprite = sprite (1)
vRect = vSprite.rect
vRect.right = vRect.right + 5
vRect.left = vRect.left - 5
vSprite.rect = vRect -
Hi, I need to create a checksum with my AScii commands, the checksum is the unsigned sum of the ASCII values reduced to the lower 8 bits. These 8 bits are then sent to a hexadecimal number in ASCII. I think it means I convert all characters in my ASCII 8 bit command and add them up. I then use a 255 and the remaining 8 bits are converted to hex and added to my order as ASCII characters. 1 / this sounds not correct and 2 / are there examples of this. I checked a little out but do not know if they are correct for me.
Something like that? The format of % 02 x format string formats a number to a hexadecimal number with 0 s leader, minimum length of 2 characters. Because you specified the lower case, I had to add the function of tiny.
Maybe you are looking for
-
Satellite Pro L10: The laptop usable continuous 24/7?
I read in an article that portable computers (especially their fans) are not designed to run 24/7. Is this true? Y at - it a specification on the fan? Laptop computer in question: Satellite Pro L10 15th PSL Thank youChris
-
How to turn the light on the keyboard on Satellite A300
Hey guys... I bought this Satellite A300. For some time and am experiencing this problem of rediciolus.I couldn't turn on the light of the keys on the keyboard... Please help me guys.I have everything working in the dark... thnx
-
I accidentally uninstalled audio beats on my computer, can I get it back?
I accidentally disabled my computer audio beats. When I press the beat button on my keyboard (I have an HP touchsmart PC running on windos 7 64 bit 520) I have doesn't respond, I can't turn the program on or off, and yet I can open the program, is th
-
Windows could not start. A recent hardware or software change might be the cause. To solve the problem: 1. Insert your windows installation disc and restart your computer.2. choose your language settings, and then click "next".3. click on "Repair you
-
Hello I have a security problem on my Q10. Some sort of spyware has been installed, I did a Wipe of security but I have doubts if it is deleted. Could you please help and tell me what can I do to erase all data on my BB and that system restore? Thank