Search Results

Search found 364 results on 15 pages for 'mouseevent'.

Page 5/15 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • BOX2D and AS3: Mouse Event not working

    - by Gabriel Meono
    Background: Trying to make a simple "drop the ball" game. The code is located inside the first frame of the timeline. Nothing more is on the stage. Issue: Using QuickBox2D I made a simple If statement that drops and object acording the Mouse-x position: if (MouseEvent.CLICK) { sim.addCircle({x:mouseX, y:1, radius:0.25, density:5}); I imported the MouseEvent library: import flash.events.MouseEvent; Nothing happens if I click, no output errors either. See it in action: http://gabrielmeono.com/download/Lucky_Hit_Alpha.swf http://gabrielmeono.com/download/Lucky_Hit_Alpha.fla Full Code: [SWF(width = 350, height = 600, frameRate = 60)] import com.actionsnippet.qbox.*; import flash.events.MouseEvent; var sim:QuickBox2D = new QuickBox2D(this); sim.createStageWalls(); //var ball:sim.addCircle({x:mouseX, y:1, radius:0.25, density:5}); // // make a heavy circle sim.addCircle({x:3, y:1, radius:0.25, density:5}); sim.addCircle({x:2, y:1, radius:0.25, density:5}); sim.addCircle({x:4, y:1, radius:0.25, density:5}); sim.addCircle({x:5, y:1, radius:0.25, density:5}); sim.addCircle({x:6, y:1, radius:0.25, density:5}); // create a few platforms sim.addBox({x:3, y:2, width:4, height:0.2, density:0, angle:0.1}); // make 26 dominoes for (var i:int = 0; i<7; i++){ //End sim.addCircle({x:1 + i * 1.5, y:16, radius:0.1, density:0}); sim.addCircle({x:2 + i * 1.5, y:15, radius:0.1, density:0}); //Mid end sim.addCircle({x:0 + i * 2, y:14, radius:0.1, density:0}); sim.addCircle({x:0 + i * 2, y:13, radius:0.1, density:0}); sim.addCircle({x:0 + i * 2, y:12, radius:0.1, density:0}); sim.addCircle({x:0 + i * 2, y:11, radius:0.1, density:0}); sim.addCircle({x:0 + i * 2, y:10, radius:0.1, density:0}); //Middle Start sim.addCircle({x:0 + i * 1.5, y:09, radius:0.1, density:0}); sim.addCircle({x:1 + i * 1.5, y:08, radius:0.1, density:0}); sim.addCircle({x:0 + i * 1.5, y:07, radius:0.1, density:0}); sim.addCircle({x:1 + i * 1.5, y:06, radius:0.1, density:0}); } if (MouseEvent.CLICK) { sim.addCircle({x:mouseX, y:1, radius:0.25, density:5}); sim.start(); /*sim.mouseDrag();*/ }

    Read the article

  • Bring object to the front, in Flash AS3

    - by jimbo
    Hi All, i have the below code, which is basically animating object across the screen, when roll-over happens it pauses the anim, and displays some information. Everything works fine, but when its paused, i wold like that current object to be 'on top' so other items run behind. I have looked at setChildIndex, but didn't have much luck. package { import flash.display.MovieClip; import flash.display.Sprite; import flash.events.MouseEvent; import flash.geom.Point; import flash.events.KeyboardEvent; import flash.events.*; import caurina.transitions.Tweener; import fl.motion.Color; public class carpurchase extends Sprite { public function carpurchase() { var carX = 570; //Set cars var car1:fullCar = new fullCar(); car1.info.alpha = 0; //var c:Color = new Color(); //c.setTint(0xff0000, 0.8); //car2.car.transform.colorTransform=c; car1.x = carX; car1.y = 280; car1.info.title.text = "test"; car1.info.desc.text = "test"; addChild(car1); car1.addEventListener(MouseEvent.ROLL_OVER, carPause); car1.addEventListener(MouseEvent.ROLL_OUT, carContinue); function car1Reset():void { Tweener.addTween(car1, {x:carX, time:0, onComplete:car1Tween}); } function car1Tween():void { Tweener.addTween(car1, {x:-120, time:2, delay:3, transition:"linear", onComplete:car1Reset}); } car1Tween(); var car2:fullCar = new fullCar(); car2.info.alpha = 0; var c:Color = new Color(); c.setTint(0xff0000, 0.8); car2.car.transform.colorTransform=c; car1.x = carX; car2.y = 175; car2.info.title.text = "test"; car2.info.desc.text = "test"; addChild(car2); car2.addEventListener(MouseEvent.ROLL_OVER, carPause); car2.addEventListener(MouseEvent.ROLL_OUT, carContinue); function car2Reset():void { Tweener.addTween(car2, {x:carX, time:0, onComplete:car2Tween}); } function car2Tween():void { Tweener.addTween(car2, {x:-120, time:3, delay:0, transition:"linear", onComplete:car2Reset}); } car2Tween(); function carPause(e:MouseEvent):void { Tweener.pauseTweens(e.target); Tweener.addTween(e.target.info, {y:-150, alpha:1, time:.5, transition:"easeout"}); } function carContinue(e:MouseEvent):void { Tweener.addTween(e.target.info, {y:10, alpha:0, time:.5, transition:"easeout"}); Tweener.resumeTweens(e.target); } } } Any help welcome

    Read the article

  • Cutom event dispatchment location

    - by Martino Wullems
    Hello, I've been looking into custom event (listeners) for quite some time, but never succeeded in making one. There are so many different mehods, extending the Event class, but also Extending the EventDispatcher class, very confusing! I want to settle with this once and for all and learn the appriopate technique. package{ import flash.events.Event; public class CustomEvent extends Event{ public static const TEST:String = 'test'; //what exac is the purpose of the value in the string? public var data:Object; public function CustomEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, data:Object = null):void { this.data = data; super(); } } } As far as I know a custom class where you set the requirements for the event to be dispatched has to be made: package { import flash.display.MovieClip; public class TestClass extends MovieClip { public function TestClass():void { if (ConditionForHoldToComplete == true) { dispatchEvent(new Event(CustomEvent.TEST)); } } } } I'm not sure if this is correct, but it should be something along the lines of this. Now What I want is something like a mouseevent, which can be applied to a target and does not require a specific class. It would have to work something like this: package com.op_pad._events{ import flash.events.MouseEvent; import flash.utils.Timer; import flash.events.TimerEvent; import flash.events.EventDispatcher; import flash.events.Event; public class HoldEvent extends Event { public static const HOLD_COMPLETE:String = "hold completed"; var timer:Timer; public function SpriteEvent(type:String, bubbles:Boolean=true, cancelable:Boolean=false) { super( type, bubbles, cancelable ); timer = new Timer(1000, 1); //somehow find the target where is event is placed upon -> target.addEventlistener target.addEventListener(MouseEvent.MOUSE_DOWN, startTimer); target.addEventListener(MouseEvent.MOUSE_UP, stopTimer); } public override function clone():Event { return new SpriteEvent(type, bubbles, cancelable); } public override function toString():String { return formatToString("MovieEvent", "type", "bubbles", "cancelable", "eventPhase"); } ////////////////////////////////// ///// c o n d i t i o n s ///// ////////////////////////////////// private function startTimer(e:MouseEvent):void { timer.start(); timer.addEventListener(TimerEvent.TIMER_COMPLETE, complete); } private function stopTimer(e:MouseEvent):void { timer.stop() } public function complete(e:TimerEvent):void { dispatchEvent(new HoldEvent(HoldEvent.HOLD_COMPLETE)); } } } This obviously won't work, but should give you an idea of what I want to achieve. This should be possible because mouseevent can be applied to about everything.The main problem is that I don't know where I should set the requirements for the event to be executed to be able to apply it to movieclips and sprites. Thanks in advance

    Read the article

  • Flash AS3 button eventlistener array bug

    - by Tyler Pepper
    Hi there, this is my first time posting a question here. I have an array of 12 buttons on a timeline that when first visiting that part of the timeline, get a CLICK eventlistener added to them using a for loop. All of them work perfectly at that point. When you click one it plays a frame label inside the specific movieClip and reveals a bio on the corresponding person with a close button and removes the CLICK eventlisteners for each button, again using a for loop. The close button plays a closing animation, and then the timeline goes back to the first frame (the one with the 12 buttons on it) and the CLICK eventlisteners are re-added, but now only the first 9 buttons of the array work. There are no output errors and the code to re-add the eventlisteners is exactly the same as the first time that works. I am completely at a loss and am wondering if anyone else has run into this problem. All of my buttons are named correctly, there are absolutely no output errors (I've used the debug module) and I made sure the array with the buttons in it is outputting all 12 at the moment the close button is clicked to add the eventlisteners back. for (var q = 0; q < ackBoDBtnArray.length; q++){ contentArea_mc.acknowledgements_mc.BoD_mc[ackBoDBtnArray[q]].addEventListener(MouseEvent.CLICK, showBio); } private function showBio(eo:MouseEvent):void { trace("show the bio"); bodVar = ackBoDBtnArray.getIndex(eo.target.name); contentArea_mc.acknowledgements_mc.BoD_mc.gotoAndPlay(ackBoDPgArray[bodVar]); contentArea_mc.acknowledgements_mc.BoD_mc.closeBio_btn.addEventListener(MouseEvent.CLICK, hideBio); for (var r = 0; r < ackBoDBtnArray.length; r++){ contentArea_mc.acknowledgements_mc.BoD_mc[ackBoDBtnArray[r]].mouseEnabled = false; contentArea_mc.acknowledgements_mc.BoD_mc[ackBoDBtnArray[r]].removeEventListener(MouseEvent.CLICK, showBio); } } private function hideBio(eo:MouseEvent):void { trace("hide it!"); contentArea_mc.acknowledgements_mc.BoD_mc.closeBio_btn.removeEventListener(MouseEvent.CLICK, hideBio); contentArea_mc.acknowledgements_mc.BoD_mc.gotoAndPlay(ackBoDClosePgArray[bodVar]); for (var s = 0; s < ackBoDBtnArray.length; s++){ trace(ackBoDBtnArray[s]); contentArea_mc.acknowledgements_mc.BoD_mc[ackBoDBtnArray[s]].mouseEnabled = true; contentArea_mc.acknowledgements_mc.BoD_mc[ackBoDBtnArray[s]].addEventListener(MouseEvent.CLICK, showBio); } Thanks in advance for any help and insight you can provide...I have a slight feeling that its something that may be obvious to another set of eyes...haha.

    Read the article

  • save button error in AS project

    - by Rajeev
    Whats wrong with the following code,There is an error at saveButton.visible = false; discardButton.visible = false; package { import flash.display.Sprite; import flash.media.Camera; import flash.media.Video; import flash.display.BitmapData; import flash.display.Bitmap; import flash.events.MouseEvent; import flash.net.FileReference; import flash.utils.ByteArray; import com.adobe.images.JPGEncoder; public class caml extends Sprite { private var camera:Camera = Camera.getCamera(); private var video:Video = new Video(); private var bmd:BitmapData = new BitmapData(320,240); private var bmp:Bitmap; private var fileReference:FileReference = new FileReference(); private var byteArray:ByteArray; private var jpg:JPGEncoder = new JPGEncoder(); public function caml() { saveButton.visible = false; discardButton.visible = false; saveButton.addEventListener(MouseEvent.MOUSE_UP, saveImage); discardButton.addEventListener(MouseEvent.MOUSE_UP, discard); capture.addEventListener(MouseEvent.MOUSE_UP, captureImage); if (camera != null) { video.smoothing = true; video.attachCamera(camera); video.x = 140; video.y = 40; addChild(video); } else { trace("No Camera Detected"); } } private function captureImage(e:MouseEvent):void { bmd.draw(video); bmp = new Bitmap(bmd); bmp.x = 140; bmp.y = 40; addChild(bmp); capture.visible = false; saveButton.visible = true; discardButton.visible = true; } private function saveImage(e:MouseEvent):void { byteArray = jpg.encode(bmd); fileReference.save(byteArray, "Image.jpg"); removeChild(bmp); saveButton.visible = false; discardButton.visible = false; capture.visible = true; } private function discard(e:MouseEvent):void { removeChild(bmp); saveButton.visible = false; discardButton.visible = false; capture.visible = true; } } }

    Read the article

  • Upload picture directly to the server

    - by Rajeev
    In the following link http://www.tuttoaster.com/create-a-camera-application-in-flash-using-actionscript-3/ how to make the picture upload directly to the server after taking a picture from webcam package { import flash.display.Sprite; import flash.media.Camera; import flash.media.Video; import flash.display.BitmapData; import flash.display.Bitmap; import flash.events.MouseEvent; import flash.net.FileReference; import flash.utils.ByteArray; import com.adobe.images.JPGEncoder; public class caml extends Sprite { private var camera:Camera = Camera.getCamera(); private var video:Video = new Video(); private var bmd:BitmapData = new BitmapData(320,240); private var bmp:Bitmap; private var fileReference:FileReference = new FileReference(); private var byteArray:ByteArray; private var jpg:JPGEncoder = new JPGEncoder(); public function caml() { saveButton.visible = false; discardButton.visible = false; saveButton.addEventListener(MouseEvent.MOUSE_UP, saveImage); discardButton.addEventListener(MouseEvent.MOUSE_UP, discard); capture.addEventListener(MouseEvent.MOUSE_UP, captureImage); if (camera != null) { video.smoothing = true; video.attachCamera(camera); video.x = 140; video.y = 40; addChild(video); } else { trace("No Camera Detected"); } } private function captureImage(e:MouseEvent):void { bmd.draw(video); bmp = new Bitmap(bmd); bmp.x = 140; bmp.y = 40; addChild(bmp); capture.visible = false; saveButton.visible = true; discardButton.visible = true; } private function saveImage(e:MouseEvent):void { byteArray = jpg.encode(bmd); fileReference.save(byteArray, "Image.jpg"); removeChild(bmp); saveButton.visible = false; discardButton.visible = false; capture.visible = true; } private function discard(e:MouseEvent):void { removeChild(bmp); saveButton.visible = false; discardButton.visible = false; capture.visible = true; } } }

    Read the article

  • How do I check on non-transparent pixels in a bitmapdata?

    - by Opoe
    I'm still working on my window cleaning game from one of my previous questions I marked a contribution as my answer, but after all this time I can't get it to work and I have to many questions about this so I decided to ask some more about it. As a sequel on my mentioned previous question, my question to you is: How can I check whether or not a bitmapData contains non transparent pixels? Subquestion: Is this possible when the masked image is a movieclip? Shouldn't I use graphics instead? Information I have: A dirtywindow movieclip on the bottom layer and a clean window movieclip on layer 2(mc1) on the layer above. To hide the top layer(the dirty window) I assign a mask to it. Code // this creates a mask that hides the movieclip on top var mask_mc:MovieClip = new MovieClip(); addChild(mask_mc) //assign the mask to the movieclip it should 'cover' mc1.mask = mask_mc; With a brush(cursor) the player wipes of the dirt ( actualy setting the fill from the mask to transparent so the clean window appears) //add event listeners for the 'brush' brush_mc.addEventListener(MouseEvent.MOUSE_DOWN,brushDown); brush_mc.addEventListener(MouseEvent.MOUSE_UP,brushUp); //function to drag the brush over the mask function brushDown(dragging:MouseEvent):void{ dragging.currentTarget.startDrag(); MovieClip(dragging.currentTarget).addEventListener(Event.ENTER_FRAME,erase) ; mask_mc.graphics.moveTo(brush_mc.x,brush_mc.y); } //function to stop dragging the brush over the mask function brushUp(dragging:MouseEvent):void{ dragging.currentTarget.stopDrag(); MovieClip(dragging.currentTarget).removeEventListener(Event.ENTER_FRAME,erase); } //fill the mask with transparant pixels so the movieclip turns visible function erase(e:Event):void{ with(mask_mc.graphics){ beginFill(0x000000); drawRect(brush_mc.x,brush_mc.y,brush_mc.width,brush_mc.height); endFill(); } }

    Read the article

  • AS3 How to check on non transparent pixels in a bitmapdata?

    - by Opoe
    I'm still working on my window cleaning game from one of my previous questions I marked a contribution as my answer, but after all this time I can't get it to work and I have to many questions about this so I decided to ask some more about it. As a sequel on my mentioned previous question, my question to you is: How can I check whether or not a bitmapData contains non transparent pixels? Subquestion: Is this possible when the masked image is a movieclip? Shouldn't I use graphics instead? Information I have: A dirtywindow movieclip on the bottom layer and a clean window movieclip on layer 2(mc1) on the layer above. To hide the top layer(the dirty window) I assign a mask to it. Code // this creates a mask that hides the movieclip on top var mask_mc:MovieClip = new MovieClip(); addChild(mask_mc) //assign the mask to the movieclip it should 'cover' mc1.mask = mask_mc; With a brush(cursor) the player wipes of the dirt ( actualy setting the fill from the mask to transparent so the clean window appears) //add event listeners for the 'brush' brush_mc.addEventListener(MouseEvent.MOUSE_DOWN,brushDown); brush_mc.addEventListener(MouseEvent.MOUSE_UP,brushUp); //function to drag the brush over the mask function brushDown(dragging:MouseEvent):void{ dragging.currentTarget.startDrag(); MovieClip(dragging.currentTarget).addEventListener(Event.ENTER_FRAME,erase) ; mask_mc.graphics.moveTo(brush_mc.x,brush_mc.y); } //function to stop dragging the brush over the mask function brushUp(dragging:MouseEvent):void{ dragging.currentTarget.stopDrag(); MovieClip(dragging.currentTarget).removeEventListener(Event.ENTER_FRAME,erase); } //fill the mask with transparant pixels so the movieclip turns visible function erase(e:Event):void{ with(mask_mc.graphics){ beginFill(0x000000); drawRect(brush_mc.x,brush_mc.y,brush_mc.width,brush_mc.height); endFill(); } }

    Read the article

  • Custom JComponent not displaying in Custom JPanel

    - by Trizicus
    I've tried the add() method but nothing is displayed when I try to add Test to GraphicsTest. How should I be adding it? Can someone show me? I've included the code I'm using. import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JComponent; public class Test extends JComponent { Test() { setOpaque(false); setBackground(Color.white); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(Color.red); g2d.drawString("Hello", 50, 50); g2d.dispose(); } } import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.geom.Rectangle2D; import javax.swing.JPanel; public class GraphicsTest extends JPanel implements MouseListener { private Graphics2D g2d; private String state; private int x, y; GraphicsTest() { add(new Test()); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); g2d = (Graphics2D) g; g2d.setColor(Color.BLACK); g2d.drawString("STATE: " + state, 5, 15); g2d.drawString("Mouse Position: " + x + ", " + y, 5, 30); g2d.setColor(Color.red); Rectangle2D r2d = new Rectangle2D.Double(x, y, 10, 10); g2d.draw(r2d); g2d.dispose(); } public void setState(String state) { this.state = state; } public String getState() { return state; } public void setX(int x) { this.x = x; repaint(); } public void setY(int y) { this.y = y; repaint(); } public void mouseClicked(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} }

    Read the article

  • actionscript 3 addchild within child and fade

    - by steve
    Here is my current code: import flash.display.*; import fl.transitions.*; import flash.events.MouseEvent; stop(); var container:MovieClip = new MovieClip(); container.width = 450; container.height = 450; container.x = 450; container.y = 0; var closeBtn:close_btn = new close_btn(); closeBtn.x = 850; closeBtn.y = 15; var bagLink:MovieClip = new bag_link_mc(); bagLink.x = 900; bagLink.y = 0; menu_bag_button.addEventListener(MouseEvent.CLICK, bagClick); function bagClick(event:MouseEvent):void{ if(MovieClip(root).currentFrame == 850) { } else { MovieClip(root).addChild (bagLink); MovieClip(root).addChild (closeBtn); MovieClip(root).gotoAndPlay(806); } } closeBtn.addEventListener(MouseEvent.CLICK, closeBag); function closeBag (event:MouseEvent):void{ MovieClip(root).removeChild(bagLink); MovieClip(root).removeChild(closeBtn); MovieClip(root).gotoAndPlay(850); } I need the first mouse function (bagClick) to create the bagLink within the container movieclip variable. I tried change it to this, but it didn't work: else { MovieClip(root).addchild (container); MovieClip(root).container.addChild (bagLink); MovieClip(root).addChild (closeBtn); MovieClip(root).gotoAndPlay(806); } I'm also trying to make "container" or "bagLink" fade in when it loads but that doesn't work either. Any help is appreciated.

    Read the article

  • actionscript 3 addchild within child and fade

    - by steve
    Here is my current code: import flash.display.*; import fl.transitions.*; import flash.events.MouseEvent; stop(); var container:MovieClip = new MovieClip(); container.width = 450; container.height = 450; container.x = 450; container.y = 0; var closeBtn:close_btn = new close_btn(); closeBtn.x = 850; closeBtn.y = 15; var bagLink:MovieClip = new bag_link_mc(); bagLink.x = 900; bagLink.y = 0; menu_bag_button.addEventListener(MouseEvent.CLICK, bagClick); function bagClick(event:MouseEvent):void{ if(MovieClip(root).currentFrame == 850) { } else { MovieClip(root).addChild (bagLink); MovieClip(root).addChild (closeBtn); MovieClip(root).gotoAndPlay(806); } } closeBtn.addEventListener(MouseEvent.CLICK, closeBag); function closeBag (event:MouseEvent):void{ MovieClip(root).removeChild(bagLink); MovieClip(root).removeChild(closeBtn); MovieClip(root).gotoAndPlay(850); } I need the first mouse function (bagClick) to create the bagLink within the container movieclip variable. I tried change it to this, but it didn't work: else { MovieClip(root).addchild (container); MovieClip(root).container.addChild (bagLink); MovieClip(root).addChild (closeBtn); MovieClip(root).gotoAndPlay(806); } I'm also trying to make "container" or "bagLink" fade in when it loads but that doesn't work either. Any help is appreciated.

    Read the article

  • Combine Text with a Draggable Mask AS3.0

    - by RC
    So I have an image that is the size of the stage: img_mc. Then I drew a small rectangle: mask_mc. The idea is to make a "window" of the small rectangle, view img_mc through the window, and be able to drag the window around. The following code works fine but I want to add text to the mask - "Drag Me!" or whatever. But if I group text with the mask it breaks down. If I make a separate text_mc I can drag it around but it's not part of the mask. How can I combine text with a mask? (sorry if this question is pathetically easy!) Thanks for any thoughts you can share! img_mc.mask = mask_mc; mask_mc.buttonMode = true; img_mc.cacheAsBitmap = true; //because I blurred the mask text_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragF); mask_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragF); stage.addEventListener(MouseEvent.MOUSE_UP, dropF); function dragF(event:MouseEvent):void{ mask_mc.startDrag(); } function dropF(event:MouseEvent):void{ mask_mc.stopDrag(); }

    Read the article

  • as3 - controlling flicker when scaling up a button or movieclip

    - by sol
    This is a situation I run into a lot but never seem to find a good solution. I have movieclips that I scale up slightly on rollover, but if you hover over the edge of the movieclip it just sits there and flickers, continuously receiving mouseOver and mouseOut events. How do you deal with this? Again, it's usually a problem when tweening the scale of a movieclip or button. my_mc.addEventListener(MouseEvent.MOUSE_OVER, mOver); my_mc.addEventListener(MouseEvent.MOUSE_OUT, mOut); private function mOver(m:MouseEvent) { TweenLite.to(m.target, .2, { scaleX:1.1, scaleY:1.1} ); } private function mOut(m:MouseEvent) { TweenLite.to(m.target, .2, { scaleX:1, scaleY:1} ); }

    Read the article

  • count clicks using actionscript 3.0 in flash

    - by Michael Stone
    I want to change the variable value based on the number of clicks. So if you click the button once, the cCount should equal 1 and twice it should equal 2. Right now all I'm returning for the value is 0, no matter the amount of clicks. Any ideas? btnRaw.addEventListener(MouseEvent.CLICK, flip); btnRaw.addEventListener(MouseEvent.MOUSE_UP,count); //create the flipping function //create the variable to store the click count var cCount:Number = 0; function flip(Event:MouseEvent):void{ raw_patty_mc.gotoAndPlay(1); } function count(Event:MouseEvent):void{ cCount = cCount+1; if(cCount>3 || cCount<6){ titleText.text="See you're doing a great job at flipping the burger! "+String(cCount); } }

    Read the article

  • addChild to root and fade in

    - by steve
    Still very newbish at Actionscript. Trying to get a website done for class on wednesday, but I can't get this one thing down. Currently there's the main timeline, then a movieclip called menu_mc, and within that are a bunch of buttons. For now, I only have one button scripted. When the button is scripted, I want a movieclip with content embedded in it to fade in on the right side, along with a close button. I can get the movie/button to appear and close, but I can't get them to fade in and out. This is what I have: import flash.display.*; import fl.transitions.*; import flash.events.MouseEvent; stop(); var closeBtn:close_btn = new close_btn(); closeBtn.x = 850; closeBtn.y = 15; var bagLink:MovieClip = new bag_link_mc(); bagLink.x = 900; bagLink.y = 0; menu_bag_button.addEventListener(MouseEvent.CLICK, bagClick); function bagClick(event:MouseEvent):void{ if(MovieClip(root).currentFrame == 850) { } else { MovieClip(root).addChild (bagLink); MovieClip(root).addChild (closeBtn); MovieClip(root).gotoAndPlay(806); } } closeBtn.addEventListener(MouseEvent.CLICK, closeBag); function closeBag (event:MouseEvent):void{ MovieClip(root).removeChild(bagLink); MovieClip(root).removeChild(closeBtn); MovieClip(root).gotoAndPlay(850); }

    Read the article

  • I need a true mouseOver...

    - by invertedSpear
    Ok, so mouseOver and RollOver, and their respective outs work great as long as your mouse is actually over the item, or one of it's children. My problem is that I may have another UI component "between" my mouse and the item I want to process the mouse/rollover(maybe a button that is on top of a canvas, but is not a child of the canvas). The mouse is still over the component, there's just something else that it's over at the same time. Any tips or help how to deal with this? Let me know if I'm not being clear enough. Here is a simplified code example detailing my question copy/paste that into your flex/flash builder and you'll see what I mean: <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="500" height="226" creationComplete="ccInit()"> <mx:Script> <![CDATA[ private function ccInit():void{ myCanv.addEventListener(MouseEvent.ROLL_OVER,handleRollOver); } private function handleRollOver(evt:MouseEvent):void{ myCanv.setStyle("backgroundAlpha",1); myCanv.addEventListener(MouseEvent.ROLL_OUT,handleRollOut); } private function handleRollOut(evt:MouseEvent):void{ myCanv.setStyle("backgroundAlpha",0); myCanv.removeEventListener(MouseEvent.ROLL_OUT,handleRollOut); } ]]> </mx:Script> <mx:Canvas id="myCanv" x="10" y="10" width="480" height="200" borderStyle="solid" borderColor="#000000" backgroundColor="#FFFFFF" backgroundAlpha="0"> </mx:Canvas> <mx:Button x="90" y="50" label="Button" width="327" height="100"/> </mx:Application>

    Read the article

  • Is there any way to add a MouseListener to a Graphic object ?

    - by Fahad
    Hi, Is there any way to add a MouseListener to a Graphic object. I have this simple GUI that draw an oval. What I want is handling the event when the user clicks on the oval import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.*; public class Gui2 extends JFrame { JFrame frame = new JFrame(); MyDrawPanel drawpanel = new MyDrawPanel(); public static void main(String[] args) { Gui2 gui = new Gui2(); gui.go(); } public void go() { frame.getContentPane().add(drawpanel); // frame.addMouseListener(this); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 300); frame.setVisible(true); } } class MyDrawPanel extends JComponent implements MouseListener { public void paintComponent(Graphics g) { int red = (int) (Math.random() * 255); int green = (int) (Math.random() * 255); int blue = (int) (Math.random() * 255); Color startrandomColor = new Color(red, green, blue); red = (int) (Math.random() * 255); green = (int) (Math.random() * 255); blue = (int) (Math.random() * 255); Color endrandomColor = new Color(red, green, blue); Graphics2D g2d = (Graphics2D) g; this.addMouseListener(this); GradientPaint gradient = new GradientPaint(70, 70, startrandomColor, 150, 150, endrandomColor); g2d.setPaint(gradient); g2d.fillOval(70, 70, 100, 100); } @Override public void mouseClicked(MouseEvent e) { if ((e.getButton() == 1) && (e.getX() >= 70 && e.getX() <= 170 && e.getY() >= 70 && e .getY() <= 170)) { this.repaint(); // JOptionPane.showMessageDialog(null,e.getX()+ "\n" + e.getY()); } } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } } This Works Except it fires when the click is within a virtual box around the oval. Could anyone help me to have it fire when the click is EXACTLY on the oval. Thanks in advance.

    Read the article

  • Actionscript - Adding EventListener to multiple buttons on stage

    - by Chev
    I have a little problem with adding EventListener to multiple objects on stage. I have above 40 buttons on stage named "Button01","Button02" .. "Button40", and i'm looking for easiest way to add EventListener to all of them. Creating something like Button01.addEventListener(MouseEvent.CLICK, doSomething) Button02.addEventListener(MouseEvent.CLICK, doSomething) .. Button40.addEventListener(MouseEvent.Click, doSomething) (Notice the same function). isn't solution i'm looking for :(. Thanks in advice.

    Read the article

  • 2d java Graphics

    - by LukeG
    I am new to java 2d graphics and I have problem handling mouseclick event. Is it possible for you to tell me why there is nothing going on after updating mouse status to clicked ? What I want to do is to change the image in array at 0 2 to another image. Nothing happens tho. Thanks for your help in advance. import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.event.*; import java.awt.*; import javax.swing.ImageIcon; import javax.swing.*; public class Board extends JPanel implements MouseListener { private static boolean[] keyboardState = new boolean[525]; private static boolean[] mouseState = new boolean[3]; private static Image[][] images; Image house; int w = 0; int h = 0; int xPos; int yPos; ImageIcon ii = new ImageIcon(this.getClass().getResource("house.gif")); ImageIcon iii = new ImageIcon(this.getClass().getResource("house1.gif")); public Board() { house = ii.getImage(); h = house.getHeight(null); w = house.getWidth(null); images = new Image[10][10]; for(int i = 0; i < 10; i++) { for(int j = 0; j < 10; j++) { images[i][j] = house; } } } public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; for(int i = 0; i < 10; i++) { for(int j = 0; j < 10; j++) { g2d.drawImage(images[i][j],w*i,h*j,null); } } //g2d.drawImage(house,15,15,null); } public void checkMouse() { if(mouseState[0]) { images[0][2] = iii.getImage(); repaint(); super.repaint(); } } @Override public void mousePressed(MouseEvent e) { mouseKeyStatus(e, true); checkMouse(); } @Override public void mouseReleased(MouseEvent e) { mouseKeyStatus(e, false); repaint(); } public static boolean mouseButtonState(int button) { return mouseState[button - 1]; } private void mouseKeyStatus(MouseEvent e, boolean status) { if(e.getButton() == MouseEvent.BUTTON1) mouseState[0] = status; else if(e.getButton() == MouseEvent.BUTTON2) mouseState[1] = status; else if(e.getButton() == MouseEvent.BUTTON3) mouseState[2] = status; }

    Read the article

  • How do I make a rectangle move in an image?

    - by alicedimarco
    Basically I have an image loaded, and when I click a portion of the image, a rectangle (with no fill) shows up. If I click another part of the image again, that rectangle will show up once more. With each click, the same rectangle should appear. So far I have this code, now I don't know how to make the image appear. My image from my file directory. I have already made the code to get the image from my file directory. import java.awt.Color; import java.awt.Graphics; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; public class MP2 extends JPanel implements MouseListener{ JFrame frame; JPanel panel; int x = 0; int y = 0; String input; public MP2(){ } public static void main(String[] args){ JFrame frame = new JFrame(); MP2 panel = new MP2(); panel.addMouseListener(panel); frame.add(panel); frame.setSize(200,200); frame.setVisible(true); } public void mouseClicked(MouseEvent event) { // TODO Auto-generated method stub this.x = event.getX(); this.y = event.getY(); this.repaint(); input = JOptionPane.showInputDialog("Something pops out"); System.out.println(input); } public void mouseEntered(MouseEvent arg0) { // TODO Auto-generated method stub } public void mouseExited(MouseEvent arg0) { // TODO Auto-generated method stub } public void mousePressed(MouseEvent arg0) { // TODO Auto-generated method stub } public void mouseReleased(MouseEvent arg0) { // TODO Auto-generated method stub } public void paintComponent(Graphics g){ super.paintComponent(g); // this.setBackground(Color.white); *Sets the bg color of the panel g.setColor(new Color(255,0,0)); g.drawRect(x, y, 100, 100); } }

    Read the article

  • Trying to get focus onto JTextPane after doubleclicking on JList element (Java)

    - by Alex Cheng
    Hi all. Problem: I have the following JList which I add to the textPane, and show it upon the caret moving. However, after double clicking on the Jlist element, the text gets inserted, but the caret is not appearing on the JTextPane. This is the following code: listForSuggestion = new JList(str.toArray()); listForSuggestion.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listForSuggestion.setSelectedIndex(0); listForSuggestion.setVisibleRowCount(visibleRowCount); listScrollPane = new JScrollPane(listForSuggestion); MouseListener mouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent mouseEvent) { JList theList = (JList) mouseEvent.getSource(); if (mouseEvent.getClickCount() == 2) { int index = theList.locationToIndex(mouseEvent.getPoint()); if (index >= 0) { Object o = theList.getModel().getElementAt(index); //System.out.println("Double-clicked on: " + o.toString()); //Set the double clicked text to appear on textPane String completion = o.toString(); int num= textPane.getCaretPosition(); textPane.select(num, num); textPane.replaceSelection(completion); textPane.setCaretPosition(num + completion.length()); int pos = textPane.getSelectionEnd(); textPane.select(pos, pos); textPane.replaceSelection(""); textPane.setCaretPosition(pos); textPane.moveCaretPosition(pos); } } theList.clearSelection(); Any idea on how to "de-focus" the selection on the Jlist, or make the caret appear on the JTextPane after the text insertion? I'll elaborate more if this is not clear enough. Please help, thanks!

    Read the article

  • Circle to move when mouse clicked Java

    - by Myt
    So I am really new to Java and I need a circle to move around JFrame when it's clicked, but the circle has to get random cordinates. So far this code generates a new circle every time it's clicked, but all the other circles stay there aswell, but I only need one circle to move around the frame. So maybe someone can help me a little :) public class test2 extends JFrame implements MouseListener { int height, width; public test2() { this.setTitle("Click"); this.setSize(400,400); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); addMouseListener(this); width = getSize().width; height = getSize().height; } public void paint (Graphics g) { setBackground (Color.red); g.setColor(Color.yellow); int a, b; a = -50 + (int)(Math.random()*(width+40)); b = (int)(Math.random()*(height+20)); g.fillOval(a, b, 130, 110); } public void mouseClicked(MouseEvent e) { int a, b; a = -50 + (int)(Math.random()*(width+40)); b = (int)(Math.random()*(height+20)); repaint(); } public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mousePressed(MouseEvent e){} public static void main(String arg[]){ new test2(); } }

    Read the article

  • Set the amount of rows JList show (Java)

    - by Alex Cheng
    Hi all. Problem: I have a method that creates a list from the parsed ArrayList. I manage to show the list in the GUI, without scrollbar. However, I am having problem setting it to show only the size of ArrayList. Meaning, say if the size is 6, there should only be 6 rows in the shown List. Below is the code that I am using. I tried setting the visibleRowCount as below but it does not work. I tried printing out the result and it shows that the change is made. private void createSuggestionList(ArrayList<String> str) { int visibleRowCount = str.size(); System.out.println("visibleRowCount " + visibleRowCount); listForSuggestion = new JList(str.toArray()); listForSuggestion.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listForSuggestion.setSelectedIndex(0); listForSuggestion.setVisibleRowCount(visibleRowCount); System.out.println(listForSuggestion.getVisibleRowCount()); listScrollPane = new JScrollPane(listForSuggestion); MouseListener mouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent mouseEvent) { JList theList = (JList) mouseEvent.getSource(); if (mouseEvent.getClickCount() == 2) { int index = theList.locationToIndex(mouseEvent.getPoint()); if (index >= 0) { Object o = theList.getModel().getElementAt(index); System.out.println("Double-clicked on: " + o.toString()); } } } }; listForSuggestion.addMouseListener(mouseListener); textPane.add(listScrollPane); repaint(); } To summarize: I want the JList to show as many rows as the size of the parsed ArrayList, without a scrollbar. Any ideas? Please help. Thanks. Please let me know if a picture of the problem is needed in case I did not phrase my question correctly.

    Read the article

  • actionscript 3 website load movieclips (frames) from library

    - by steve
    Here is my current code that doesn't function: import flash.display.*; import fl.transitions.*; import flash.events.MouseEvent; stop(); var contentBox:MovieClip = new MovieClip(); contentBox.width = 400; contentBox.height = 500; contentBox.x = 400; contentBox.y = 0; var closeBtn:close_btn = new close_btn(); closeBtn.x = 850; closeBtn.y = 15; var bagLink:MovieClip = new bag_link_mc(); bagLink.x = 900; bagLink.y = 0; menu_bag_button.addEventListener(MouseEvent.CLICK, bagClick); function bagClick(event:MouseEvent):void{ if(MovieClip(root).currentFrame == 835) { } else { MovieClip(root).addChild (contentBox); MovieClip(root).contentBox.addChild (bagLink); MovieClip(root).contentBox.addChild (closeBtn); MovieClip(root).gotoAndPlay(806); } } closeBtn.addEventListener(MouseEvent.CLICK, closeBag); function closeBag (event:MouseEvent):void{ MovieClip(root).removeChild(contentBox); MovieClip(root).gotoAndPlay(850); } I don't know ActionScript at all, so this may be the complete wrong way of approaching it. The setup is as follows: site loads, there's a big menu in the center (frame 805). When you click on a menu item from there, the whole menu moves to the side, and the right side I want a "contentBox" movieclip, filled with "bagLink" (which is site content) and to have a close button (closeBtn.) It also needs to know that if you click the same link again on the left side that it doesn't reanimate, it just stays (which I achieved with the "if" statement.) Finally, if someone clicks another link, it needs to clear "contentBox" and refill it with whatever movieClip that was clicked. I know this is a lot to ask, but I'm in dire need of help as this is due on Wednesday...

    Read the article

  • How to detect collisions in AS3?

    - by Gabriel Meono
    I'm trying to make a simple game, when the ball falls into certain block, you win. Mechanics: The ball falls through several obstacles, in the end there are two blocks, if the ball touches the left block you win, the next level will contain more blocks and less space between them. Test the movie (click on the screen to drop the ball): http://gabrielmeono.com/downloads/Lucky_Hit_Alpha.swf These are the main variables: var winBox:QuickObject;//You win var looseBox:QuickObject;//You loose var gameBall:QuickObject;//Ball dropped Question: How do I trigger a collision function if the ball hits the winBox? (Win message/Next level) Thanks, here is the full code: package { import flash.display.MovieClip; import com.actionsnippet.qbox.*; import flash.events.MouseEvent; [SWF(width = 600, height = 600, frameRate = 60)] public class LuckyHit extends MovieClip { public var sim:QuickBox2D; var winBox:QuickObject; var looseBox:QuickObject; var gameBall:QuickObject; /** * Constructor */ public function LuckyHit() { sim = new QuickBox2D(this); //sim.createStageWalls(); winBox = sim.addBox({x:5,y:600/30, width:300/30, height:10/30, density:0}); looseBox = sim.addBox({x:15,y:600/30, width:300/30, height:10/30, density:0}); // make obstacles for (var i:int = 0; i<(stage.stageWidth/50); i++){ //End sim.addCircle({x:1 + i * 1.5, y:16, radius:0.1, density:0}); sim.addCircle({x:2 + i * 1.5, y:15, radius:0.1, density:0}); //Mid End sim.addCircle({x:0 + i * 2, y:14, radius:0.1, density:0}); sim.addCircle({x:0 + i * 2, y:13, radius:0.1, density:0}); sim.addCircle({x:0 + i * 2, y:12, radius:0.1, density:0}); sim.addCircle({x:0 + i * 2, y:11, radius:0.1, density:0}); sim.addCircle({x:0 + i * 2, y:10, radius:0.1, density:0}); //Middle Start sim.addCircle({x:0 + i * 1.5, y:09, radius:0.1, density:0}); sim.addCircle({x:1 + i * 1.5, y:08, radius:0.1, density:0}); sim.addCircle({x:0 + i * 1.5, y:07, radius:0.1, density:0}); sim.addCircle({x:1 + i * 1.5, y:06, radius:0.1, density:0}); } sim.start(); stage.addEventListener(MouseEvent.CLICK, _clicked); } /** * .. * @param e MouseEvent.CLICK */ private function _clicked(e:MouseEvent) { gameBall = sim.addCircle({x:(mouseX/30), y:(1), radius:0.25, density:5}); } } }

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >