ActionScript 3.0 :: Click-listener On Sprite Instances?
Jun 27, 2009
am loading an image onto stage dynamically. When I click on the loaded image, i am drawing a circle/rectangle[which is of Sprite type] at exact pixel-position on the image and making these circles/rectangles(Sprite_objects) visible there itself. In this way, I am adding as many number of Sprites_objects, till I continue clicking on the same image present on the stage.
The code in my application(which displays red colored rectangles when you click on the image) is as follows:
If you copy the code into ur actionsPanel directly,then make sure "image1.jpg" file * is present beside the .fla file.Since it gets loaded iff it is present in same directory.
*/ var myContainer:MovieClip = new MovieClip(); var temp_x:int,temp_y:int; //Loading an image dynamically and adding listeners... var urlReq:URLRequest=new URLRequest("image1.jpg"); var loader:Loader = new Loader(); loader.load(urlReq);[code]....
View 9 Replies
Similar Posts:
Apr 10, 2011
Taking my first steps coding in AS3. So I have my main class which extends sprite and I put new mc's on top of that. Using addEventListener on any child MC's with MouseEvent.CLICK works fine, but I can't add it to the main sprite. How can I register all clicks on the screen?
View 0 Replies
Jun 3, 2011
I am building a Custom Image Picker, that shows 6 alternative versions. However the photo is only showing on the 6th item.
_model.selectedPhoto returns a Sprite, and does not let the app function correctly.
However when I use _model.photos[ii], A photo is added to each item - Why is this? I need to add _model.selectedPhoto to each s:Sprite
for (var ii:int; ii < 6; ii++)
{
//Create BG
var s:Sprite = new Sprite();
[Code]....
View 2 Replies
Jul 16, 2009
I thought would be coded like this:
var sp:Sprite = new Sprite();
sp.graphics.beginFill(0xFF88CC);
sp.graphics.drawCircle(0, 0, 50);
[Code].....
however, I realize even tho im looping that addChild method, its still adding sp, so do I add a new naming convention in the loop, or should I be adding these instances to another display object.... this seems like such a simple thing to do yet I cant figure it out, I also want to randomize the x and y, but this first seems to be the issue I need to address.
View 1 Replies
Jun 23, 2010
I'm trying to instance a button that I've made in a for loop. Everything else works, but I'm having a problem with mousing over and out. I was intending to make it so that each label would respond to its own instanced listener, but instead only the last label is responding to the listener. So, no matter which button I mouse over, only the last button's label animates. It seems like something that's simple, so I'm going to continue trying to work with this.
Here's the loop:
Code:
for(var i=0; i<MenuButtonLabels_arr.length; i++)
{
var menuBtn:MenuButton = new MenuButton();
var MenuTextContents_mc:MenuText = new MenuText();
[Code]....
View 9 Replies
Nov 22, 2010
I have several 1000 MovieClips (representing US counties and states) on the stage after the swf is loaded. Each MovieClip has a different instance name. Currently, a user can mouse over a county in NY, for example, and I only want the boundary for the the county highlighted. However, the state boundary is also highlighted as well.
I added this type of listener at the top:
addEventListener(MouseEvent.MOUSE_OVER, someFunction);
The problem is, it is applied to all MC instances on stage. Any suggestions on how to add the event listener to only specific MC instances? I thought I could add the event listener to the layer, but does not seemed to be working. And since I have several 1000 I don't think typing out mc_instance.addEventListener for every different mc is the correct way.
View 9 Replies
Jul 10, 2009
I'm trying to write a class which can spawn many instances of a given sprite. Something like.....
package {
import flash.display.Sprite;
public class particlePlane extends Sprite{
public function particlePlane(particleType:Object, ammount:uint, planeWidth:uint, planeHeight:uint) {
trace("particlePlane: Populating with "+ammount+" "+particleType);
for (var count = 1;count <= ammount; count++) {
[Code]...
View 2 Replies
Mar 13, 2009
It's never been an issue since I always anticipate it but just wondering...
if I put a MouseEvent listener on a movieclip/sprite...
Code:
whatever.addEventListener(MouseEvent.CLICK, clickAction, false, 0, true);
function clickAction(e:MouseEvent):void {
trace(e.target);
}
that traces a movieclip inside the intended target...
View 2 Replies
Jun 8, 2009
I'm currently working on a center stage component and I was wondering if there's a good way to detect when a stage component has been changed if any of the elements inside it have been enlarged?
This seems like it should be available but I can't find one that doesn't fire before the redraw. Or at all for that matter.
View 1 Replies
Jul 17, 2009
I thought would be coded like this:
var sp:Sprite = new Sprite();
sp.graphics.beginFill(0xFF88CC);
sp.graphics.drawCircle(0, 0, 50);
[Code]....
however, I realize even tho im looping that addChild method, its still adding sp, so do I add a new naming convention in the loop, or should I be adding these instances to another display object.... this seems like such a simple thing to do yet I cant figure it out, I also want to randomize the x and y, but this first seems to be the issue I need to address.
View 6 Replies
Apr 4, 2011
I'm having trouble removing the an event listener as well as the sprite at the same time. I currently get an error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
And if I comment out removeChild, I have no error but, obviously, the sprite remains on the screen. how I can rid myself of that error?
//Bullet extends Sprite Class
bullet:Bullet = new Bullet();
mc.addChild(bullet);
[Code]....
View 3 Replies
Apr 8, 2009
Can i change the colors of two mc's if i just click one of them? i tried to put the other mc (btn02) inside the function but only btn01 changes color when i click it.
here's the code;
var controlcolor:Color = new Color(btn01);
var controlcolor2:Color = new Color(btn02);
btn01.onPress = function(){
controlcolor.setRGB(0x000000);
btn02.controlcolor2.setRGB(0x000000);
}
View 1 Replies
Apr 10, 2010
I'm getting the hang of AS3.But My Click Listener isnt working. The Rollovers are fine.[code]
View 5 Replies
Feb 16, 2009
I'm trying to add a click event listener to a mc. the listener could only work after tweenlite is finest.
the next code those nothing for me
Code:
Luister = new Object();
Luister.onPress = function() {
trace("Muisknop losgelaten.")}
[Code]....
View 0 Replies
Mar 4, 2011
I am new at AS3 and for a simple task it seems I have a lot of code but here is my problem.The code below displays wind direction and the speed of it, but I want to convert that code into a re-usable function where each time displaySprite (after adding and event listener ie: displaySprite.addEventListener(MouseEvent.MOUSE_CL ICK, clearAndRedraw); ) gets clicked it will redraw the same sprite with new information.
Code:
import flash.text.TextField;
import flash.text.TextFormat;
[code].....
View 2 Replies
Feb 8, 2009
Basically I have lot of text fields that are rendered dynamically, and I want the user to be able to right click on one and edit it.
Is it good practise to use the right-click bring up custom menu on a sprite. And is the method guaranteed to work accross all browsers? Do mac mice have right mouse click buttons?
[URL]
And if not, what would be a good work around. Maybe bringing up a yahoo astra message box with the two options one for left mouse click, one for right click and edit text field?
View 2 Replies
Oct 23, 2010
I have added a listener to the stage to close a loader object when the stage is clicked. The problem is the click seems to effect the loader object to (basically when you click the loader it calls the click function attached to the stage). Is that to be expected? I suppose it makes sense, but is there a way of adding a listener to the stage that excludes certain objects?
View 3 Replies
Dec 20, 2009
I want to add a simple piece of text to the stage and add a listener to do something when the user clicks it.
Here's my TextLink class:
package some.package {
import flash.display.Sprite;
import flash.external.ExternalInterface;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
[Code] .....
View 4 Replies
Aug 8, 2011
I have a button with a MouseEvent.CLICK listener. The CLICK event is being triggered when the button is pushed, mouse is down while rolled out, then released when rolled in on the button again. I do not want this to happen, the click event should not occur when the button is being dragged.
My flash file contains a large amount of buttons and click listeners, I would like to solve this problem with as little code as possible. What is the simplest solution to this problem?
View 2 Replies
Mar 31, 2012
I would like to know how to compose a click mouseevent of different objects in one listener, if ever that's possible.What I wanted to do is make this listener universal for all the button clicks like:
stage.addEventListener(MouseEvent.CLICK,clicker);
function clicker (e:MouseEvent):void{
if (frame2_btn is clicked){
gotoAndPlay(3);
[code]....
View 2 Replies
Jan 20, 2010
I put together this button for statement. Now if I put
ActionScript Code:
for (var m:int = 0; m<btnArray.length; m++){
btnArray[m].addEventListener(MouseEvent.CLICK, clickBtn);
function clickBtn(e:MouseEvent):void {
[Code].....
not sure what to do, it compiles correctly no errors given when buttons are clicked, it just doesn't let me do anything w/ the "pressedBtn" variable outtside of the for loop that it's in.
View 6 Replies
Feb 27, 2012
I have a button and I'd like to have the user right click on the button and then display the menu that will allow them to copy the highlighted text, but I'm getting the infamous 1119: Access of possibly undefined property RIGHT_CLICK through a reference with static type class. What am I doing wrong?
ActionScript Code:
import flash.events.MouseEvent;
stop();
[code].....
View 1 Replies
Jun 24, 2009
Here, my loader instance name is: myLoader. When I click on the dynamically loaded image, I need to place a small red rectangle at that particular pixel position on the image.For creating a small rectangle, I am using following code:
[Code]...
View 2 Replies
Sep 14, 2009
[Code]....
At the moment when I click on the continer sprite, both mouse events are bringing triggered, from the stage and the container sprite. How can I make it so I only get the object I'm clicking on and not the stage as well??
View 7 Replies
Nov 25, 2010
I am trying to attach a double click property to a listener like this button.addEventListener(MouseEvent.DOUBLE_CLICK, function); but having read the help files it says that this will not work unless you activate the doubleClickEnabled property. But i cant work out how i need to do this!
View 1 Replies
Sep 12, 2011
I would like to have a movie to play when the mouse is over a button instead of when it is clicked. My script is now:
btn1.addEventListener(MouseEvent.CLICK, buttonClick);
View 3 Replies
Apr 23, 2010
$("#listView object.modal").click(function(){
// Get the ID of the clicked link:
var link = $(this).closest("h2").attr("title");
[Code]....
This fires a modal (jQuery UI). It it working in FF, Chrome/Safari but not in IE 7/8. Is there something I'm missing here?
Big Picture: We're using a swf to render custom type and there is a link in the rendered (flash) content. We're hoping to catch the link action in the jQuery listener so we don't have to extend our swf have an optional param to return false on link click.
View 1 Replies
Feb 23, 2009
I'm trying to add an event listener inside an object but it doesn't seem to work. other OO languages it makes sense for an object to be able to attach events etc itself rather than have some external action do it.Here's an example of what I'm trying to do:
ActionScript Code:
package {
import flash.display.MovieClip;
public class Player extends MovieClip {
[CODE]....
This gives an error "1120: Access of undefined property MouseEvent." suggesting that I don't have access to MouseEvent from within the instansiated object.What I can do is create an instance of the class from the Document Class for example and then do the following:
ActionScript Code:
newInstance.addEventListener(MouseEvent.CLICK, newInstance.mouseClick);
View 1 Replies
Apr 1, 2011
I have a drop-down menu that stays open when I click it, until I click it again. I want it to close when I click away from it. So I created an event listener of type MouseEvent.CLICK and apply it to the stage.
The obvious problem is, though, that when I click the drop-down menu to make it open, I'm also clicking the stage, which prevents it from opening.
I think there's probably a simple solution to this but I'm stuck. I called stopPropagation() on the drop-down menu and that seems like it should help but it doesn't.
View 2 Replies
Mar 25, 2010
Not sure if I phrased that correctly. I have about 6 pieces of illustrator outlined text.imported into flash, set as symbols with event listeners and works fine. but i notice I can only click on the outline itself, if i click on the inside of an "o" or "R" it doesnt work.I added white boxes behind each of the symbols and that fixed the problem, but now i want to do a color transform on the symbol (the text only of course), but when I apply the transform, its the background box and the text that have the new color applied, just leaving me a rectangle. I gave the box an alpha of 0, hoping if i didn't affect the alpha in the transform, the pointer would still read the box, but no go, it doesnt even see the box again.
View 4 Replies