# Popping cursor

**URL:** <https://forum.kirupa.com/t/popping-cursor/261695>\
**Category:** Uncategorized\
**Created:** [May 29, 2008, 11:40pm UTC](https://forum.kirupa.com/t/popping-cursor/261695 "2008-05-29T23:40:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![opul777](https://avatars.discourse-cdn.com/v4/letter/o/858c86/32.png) [@opul777](https://forum.kirupa.com/u/opul777)\
**Post date:** [May 29, 2008, 11:40pm UTC](https://forum.kirupa.com/t/popping-cursor/261695/1 "2008-05-29T23:40:38Z")

</div>

hi.  
i had an earlier post about an interactive scene with bubbles. i’ve just updated the code and works quite well except the pin cursor that is meant to pop the bubbles is still not working.  
could anyone help?

here is the code:  
main class

ActionScript Code:  
[LEFT]package[COLOR=#000000]{[/COLOR] [COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]display[/COLOR]._; [COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]events[/COLOR]._; [COLOR=#993300]public[/COLOR] [COLOR=#993300]class[/COLOR] main [COLOR=#993300]extends[/COLOR] [COLOR=#993300]MovieClip[/COLOR][COLOR=#000000]{[/COLOR] [COLOR=#993300]private[/COLOR] [COLOR=#993300]var[/COLOR] myBubble:Bubble; [COLOR=#993300]public[/COLOR] [COLOR=#993300]function[/COLOR] mainCOLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR] [COLOR=#993300]for[/COLOR][COLOR=#000000]([/COLOR][COLOR=#993300]var[/COLOR] i:[COLOR=#993300]int[/COLOR] = [COLOR=#000000]0[/COLOR]; i \< [COLOR=#000000]15[/COLOR]; i++[COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR] myBubble = [COLOR=#993300]new[/COLOR] BubbleCOLOR=#000000[/COLOR]; addChildCOLOR=#000000[/COLOR]; [COLOR=#000000]}[/COLOR] [COLOR=#000000]}[/COLOR] [COLOR=#000000]}[/COLOR] [COLOR=#000000]}[/COLOR]  
[/LEFT]

bubble class

ActionScript Code:  
[LEFT]package [COLOR=#000000]{[/COLOR] [COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]display[/COLOR]._; [COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]events[/COLOR]._; [COLOR=#993300]public[/COLOR] [COLOR=#993300]class[/COLOR] Bubble [COLOR=#993300]extends[/COLOR] Sprite [COLOR=#000000]{[/COLOR] [COLOR=#993300]var[/COLOR] angle:[COLOR=#993300]Number[/COLOR]; [COLOR=#993300]var[/COLOR] randomSpeed:[COLOR=#993300]Number[/COLOR]; [COLOR=#993300]var[/COLOR] theParent:[COLOR=#993300]Object[/COLOR]; [COLOR=#993300]public[/COLOR] [COLOR=#993300]function[/COLOR] BubbleCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR] theParent = theParent; angle = [COLOR=#993300]Math[/COLOR].[COLOR=#993300]random[/COLOR]COLOR=#000000[/COLOR] \* [COLOR=#000000]140[/COLOR] - [COLOR=#000000]200[/COLOR]; randomSpeed = [COLOR=#993300]Math[/COLOR].[COLOR=#993300]random[/COLOR]COLOR=#000000[/COLOR] \* [COLOR=#000000]10[/COLOR]; [COLOR=#993300]this[/COLOR].[COLOR=#000000]x[/COLOR] = theParent.[COLOR=#993300]stage[/COLOR].[COLOR=#000000]stageWidth[/COLOR]/[COLOR=#000000]2[/COLOR].[COLOR=#000000]5[/COLOR]; [COLOR=#993300]this[/COLOR].[COLOR=#000000]y[/COLOR] = theParent.[COLOR=#993300]stage[/COLOR].[COLOR=#000000]stageHeight[/COLOR]-[COLOR=#000000]150[/COLOR]; [COLOR=#993300]this[/COLOR].[COLOR=#000000]scaleX[/COLOR] = [COLOR=#993300]this[/COLOR].[COLOR=#000000]scaleY[/COLOR] = [COLOR=#993300]Math[/COLOR].[COLOR=#993300]random[/COLOR]COLOR=#000000[/COLOR]; addEventListenerCOLOR=#000000[/COLOR]; [COLOR=#000000]}[/COLOR] [COLOR=#993300]public[/COLOR] [COLOR=#993300]function[/COLOR] floatUpCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR] [COLOR=#993300]var[/COLOR] radian:[COLOR=#993300]Number[/COLOR] = angle \* [COLOR=#993300]Math[/COLOR].[COLOR=#993300]PI[/COLOR]/[COLOR=#000000]400[/COLOR]; [COLOR=#993300]var[/COLOR] vx:[COLOR=#993300]Number[/COLOR] = [COLOR=#993300]Math[/COLOR].[COLOR=#993300]ceil[/COLOR]COLOR=#000000[/COLOR] \* randomSpeed; [COLOR=#993300]var[/COLOR] vy:[COLOR=#993300]Number[/COLOR] = [COLOR=#993300]Math[/COLOR].[COLOR=#993300]sin[/COLOR]COLOR=#000000[/COLOR] \* randomSpeed; [COLOR=#993300]this[/COLOR].[COLOR=#000000]x[/COLOR] += vx; [COLOR=#993300]this[/COLOR].[COLOR=#000000]y[/COLOR] += vy; [COLOR=#000000]}[/COLOR] [COLOR=#000000]}[/COLOR][COLOR=#000000]}[/COLOR]  
[/LEFT]

pin class

ActionScript Code:  
[LEFT]package[COLOR=#000000]{[/COLOR] [COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]display[/COLOR]._; [COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]events[/COLOR]._; [COLOR=#993300]public[/COLOR] [COLOR=#993300]class[/COLOR] Pin [COLOR=#993300]extends[/COLOR] [COLOR=#993300]MovieClip[/COLOR][COLOR=#000000]{[/COLOR] [COLOR=#993300]var[/COLOR] mypin = [COLOR=#993300]new[/COLOR] PinCOLOR=#000000[/COLOR]; [COLOR=#993300]public[/COLOR] [COLOR=#993300]function[/COLOR] addPinCOLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR] addEventListenerCOLOR=#000000[/COLOR]; addChildCOLOR=#000000[/COLOR]; mypin.[COLOR=#000000]x[/COLOR] = mouseX; mypin.[COLOR=#000000]y[/COLOR] = mouseY; mypin.[COLOR=#993300]startDrag[/COLOR]COLOR=#000000[/COLOR]; [COLOR=#000000]}[/COLOR] [COLOR=#993300]public[/COLOR] [COLOR=#993300]function[/COLOR] floatUpCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR] evt.[COLOR=#993300]target[/COLOR].[COLOR=#000000]y[/COLOR] -= evt.[COLOR=#993300]target[/COLOR].[COLOR=#000000]theParent[/COLOR]; [COLOR=#993300]if[/COLOR] [COLOR=#000000]([/COLOR]evt.[COLOR=#993300]target[/COLOR].[COLOR=#000000]hitTestPoint[/COLOR][COLOR=#000000]([/COLOR]mypin.[COLOR=#000000]x[/COLOR] - mypin.[COLOR=#993300]width[/COLOR] / [COLOR=#000000]2[/COLOR], mypin.[COLOR=#000000]y[/COLOR], [COLOR=#993300]true[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR] evt.[COLOR=#993300]target[/COLOR].[COLOR=#000000]removeEventListener[/COLOR]COLOR=#000000[/COLOR]; evt.[COLOR=#993300]target[/COLOR].[COLOR=#000000]theParent[/COLOR].[COLOR=#000000]removeChild[/COLOR]COLOR=#000000[/COLOR]; [COLOR=#000000]}[/COLOR] [COLOR=#000000]}[/COLOR] [COLOR=#000000]}[/COLOR][COLOR=#000000]}[/COLOR]  
[/LEFT]

---

<div class="post-metadata">

**Author:** ![opul777](https://avatars.discourse-cdn.com/v4/letter/o/858c86/32.png) [@opul777](https://forum.kirupa.com/u/opul777)\
**Post date:** [May 29, 2008, 11:42pm UTC](https://forum.kirupa.com/t/popping-cursor/261695/2 "2008-05-29T23:42:47Z")

</div>

sorry about the code. i didnt write it like that

---

<div class="post-metadata">

**Author:** ![opul777](https://avatars.discourse-cdn.com/v4/letter/o/858c86/32.png) [@opul777](https://forum.kirupa.com/u/opul777)\
**Post date:** [May 30, 2008, 12:12am UTC](https://forum.kirupa.com/t/popping-cursor/261695/3 "2008-05-30T00:12:54Z")

</div>

main class  
\<as\>  
package{

import flash.display._;  
import flash.events._;

public class main extends MovieClip{

private var myBubble:Bubble;

public function main(){  
for(var i:int = 0; i \< 15; i++){  
myBubble = new Bubble(this);  
addChild(myBubble);  
}  
}  
}  
}

\</as\>

bubble class  
\<as\>  
package {  
import flash.display._;  
import flash.events._;  
public class Bubble extends Sprite {  
var angle:Number;  
var randomSpeed:Number;  
var theParent:Object;  
public function Bubble(theParent) {  
theParent = theParent;  
angle = Math.random() \* 140 - 200;  
randomSpeed = Math.random() \* 10;  
this.x = theParent.stage.stageWidth/2.5;  
this.y = theParent.stage.stageHeight-150;  
this.scaleX = this.scaleY = Math.random();  
addEventListener(Event.ENTER\_FRAME,floatUp);  
}  
public function floatUp(evt:Event) {  
var radian:Number = angle \* Math.PI/400;  
var vx:Number = Math.ceil(radian) \* randomSpeed;  
var vy:Number = Math.sin(radian) \* randomSpeed;  
this.x += vx;  
this.y += vy;  
}  
}  
}  
\</as\>

pin class  
\<as\>  
package{

import flash.display._;  
import flash.events._;

public class Pin extends MovieClip{  
var mypin = new Pin();

public function addPin(evt:Event){

addEventListener(MouseEvent.MOUSE\_DOWN,addPin);  
addChild(mypin);  
mypin.x = mouseX;  
mypin.y = mouseY;  
mypin.startDrag(true);  
}

public function floatUp(evt:Event) {  
evt.target.y -= evt.target.theParent;  
if (evt.target.hitTestPoint(mypin.x - mypin.width / 2, mypin.y, true)) {  
evt.target.removeEventListener(Event.ENTER\_FRAME,floatUp);  
evt.target.theParent.removeChild(evt.target);  
}  
}  
}  
}  
\</as\>

THE CODE AGAIN

---

<div class="post-metadata">

**Author:** ![rbnzdave](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@rbnzdave](https://forum.kirupa.com/u/rbnzdave)\
**Post date:** [May 30, 2008, 12:21am UTC](https://forum.kirupa.com/t/popping-cursor/261695/4 "2008-05-30T00:21:08Z")

</div>

from what i can see you never actually create the addPin event except for inside the function addPin.

thats like locking your keys inside your car, quite literally.

---

<div class="post-metadata">

**Author:** ![opul777](https://avatars.discourse-cdn.com/v4/letter/o/858c86/32.png) [@opul777](https://forum.kirupa.com/u/opul777)\
**Post date:** [May 30, 2008, 12:23am UTC](https://forum.kirupa.com/t/popping-cursor/261695/5 "2008-05-30T00:23:44Z")

</div>

lol.  
so how do i fix this. sorry im a beginner and im trying to learn by doing. your help is great!

---

<div class="post-metadata">

**Author:** ![rbnzdave](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@rbnzdave](https://forum.kirupa.com/u/rbnzdave)\
**Post date:** [May 30, 2008, 12:37am UTC](https://forum.kirupa.com/t/popping-cursor/261695/6 "2008-05-30T00:37:13Z")

</div>

well unfortunately i use flash cs3 so chucking the code in to test it wont work.

You need to mode the addeventlistener to the main movie. you need to create the pin instance and add it from the main movie.

you can send me the files if you like and I’ll sort it from there.

---

<div class="post-metadata">

**Author:** ![opul777](https://avatars.discourse-cdn.com/v4/letter/o/858c86/32.png) [@opul777](https://forum.kirupa.com/u/opul777)\
**Post date:** [May 30, 2008, 12:53am UTC](https://forum.kirupa.com/t/popping-cursor/261695/7 "2008-05-30T00:53:38Z")

</div>

hey here are the files.  
i cant send the .fla its actualy to big…

is this a big process or is it quite simple

---

<div class="post-metadata">

**Author:** ![opul777](https://avatars.discourse-cdn.com/v4/letter/o/858c86/32.png) [@opul777](https://forum.kirupa.com/u/opul777)\
**Post date:** [May 30, 2008, 2:17am UTC](https://forum.kirupa.com/t/popping-cursor/261695/8 "2008-05-30T02:17:58Z")

</div>

any luck? ive tried but im not having much luck at all lol
