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.
Tags: BlackBerry Developers
Similar Questions
-
Hello
by clicking on the search icon, a search bar will be visible (ON)
If the user clicks any where on the scene, the search bar will be NO visible (OFF) OR user, click the ICON again the search bar will be OFF
but this point CLICK fires without clicking
searchIcon.addEventListener(MouseEvent.CLICK, showSearch); var srchBox:Boolean = true; function showSearch(event:MouseEvent):void { if(srchBox) { srch.visible = true; stage.addEventListener(MouseEvent.CLICK, offSearch); srchBox = false; } else{ srch.visible = false; srchBox = true; stage.removeEventListener(MouseEvent.CLICK, offSearch); } } function offSearch(event:MouseEvent):void { srch.visible = false; stage.removeEventListener(MouseEvent.CLICK, offSearch); }
staged as I click the ICON, icon triggered and search bar > OFF
:
searchIcon.addEventListener(MouseEvent.CLICK, showSearch); var srchBox:Boolean = true; function showSearch(event:MouseEvent):void{ if(srchBox) { srch.visible = true; stage.addEventListener(MouseEvent.CLICK, offSearch); srchBox = false; } else{ event.stopPropagation(); srch.visible = false; srchBox = true; stage.removeEventListener(MouseEvent.CLICK, offSearch); } } function offSearch(event:MouseEvent):void { srch.visible = false; stage.removeEventListener(MouseEvent.CLICK, offSearch); }
-
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 -
Sometimes when I start my PC I have a black screen with the Windows boot manager at the top. Although there are several options available, that nothing happens no matter what keys I hit and the only option is to shut down the computer and restart completely. Sometimes the Boot Manager page turns and my office sometimes opens fine. I've updated with everything Microsoft has Windows Vista and I still get this screen. Anyone has any ideas.
Do a startup repair and see if that fixes it:
Download the ISO on the link provided and make a record of repair time it starts.
Go to your Bios/Setup, or the Boot Menu at startup and change the Boot order to make the DVD/CD drive 1st in the boot order, then reboot with the disk in the drive.
At the startup/power on you should see at the bottom of the screen either F2 or DELETE, go to Setup/Bios or F12 for the Boot Menu.
When you have changed that, insert the Bootable disk you did in the drive and reboot.
http://www.bleepingcomputer.com/tutorials/tutorial148.html
Link above shows what the process looks like and a manual, it load the repair options.
NeoSmart containing the content of the Windows Vista DVD 'Recovery Centre', as we refer to him. It cannot be used to install or reinstall Windows Vista, and is just a Windows PE interface to recovering your PC. Technically, we could re-create this installation with downloadable media media freely from Microsoft (namely the Microsoft WAIK, several gigabyte download); but it is pretty darn decent of Microsoft to present Windows users who might not be able to create such a thing on their own.
Read all the info on the website on how to create and use:
http://NeoSmart.net/blog/2008/Windows-Vista-recovery-disc-download/
ISO Burner: http://www.snapfiles.com/get/active-isoburner.html
It's a very good Vista startup repair disk.
You can do a system restart tool, system, etc it restore.
It is NOT a disc of resettlement.
And the 32-bit is what normally comes on a computer, unless 64-bit.
See you soon.
Mick Murphy - Microsoft partner
-
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.
-
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)
endThen 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
endNow, 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.
-
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
Maybe you are looking for
-
HP 35s - normal probability function
Hi all I am trying to determine if the 35s has an 'automatic' integrated in the prerequisite programs normal probability function. For anyone who uses Stata, you can type "normal di (value)", and you get a returned probability based on the normal di
-
Qosmio G30 - HDD2 not found after replacement
The lack of HARD drive capacity, I replaced drive HARD n ° 2 (drive D :) on my Qosmio G30 with a bigger (640 GB instead of 200 GB).The startup is going well, Windows 7 starts immediately. But the HDD is not shown in the 'Computer' window (the replace
-
Sanitizer spilled in my iPod and now it will not load. What is the problem with i?
Disinfectant for spilled in my iPod (5th generation), and now it will not load. What is wrong with him? I could clearly see inside the screen before he died. I have biught a new charger thinking mines was just broke, but he does not always load.
-
Original title: extended error code = Oxfof4 I have a couple of different symptoms. My laptop acts like it doesn't even have wireless capabilities although the exact model the same sitting next to her was a strong wireless signal (I still had interne
-
Try to install the update kb2538243 get error code643
Why is it not be able to update? He returned as failed