-
MC going to mouse and delete.
Hello everyone.
I have a problem. At the moment I've got a missile launcher firing in the direction I'm aiming, with acceleration effect, etc, well, no prob.
But I want to make my missile going to a saved mouse location, and be deleted here.
Here is my missile script :
Actionscript Code:
package { import flash.display.*; import flash.events.*; public class MissileSimple extends MovieClip { var xSpeed:Number; var ySpeed:Number; var MissileAngle:Number; var MissileSpeed:Number; var Acceleration:Number = 1; public function MissileSimple() { this.addEventListener(Event.ADDED, Launch); } function Launch(event:Event):void { MissileSpeed = 1; MissileAngle = MovieClip(root).SiloRotDeg * Math.PI / 180; xSpeed = Math.cos(MissileAngle) * MissileSpeed; ySpeed = Math.sin(MissileAngle) * MissileSpeed; this.addEventListener(Event.ENTER_FRAME, runEnterFrame); } function runEnterFrame(event:Event):void { Acceleration += 0.3; this.x += xSpeed * Acceleration; this.y += ySpeed * Acceleration; } } }
Can someone explain me how I do to make my missile disappear at the "click" mouse location ? (They can be multiple missile fired at a same time and they must have their OWN saved location). They are not homing missile, just going to the location when the player click.
Thanks ! <3
Last edited by Gnougnou; 06-05-2012 at 03:09 PM.
-
Actionscript Code:
missile.addEventListener(MouseEvent.CLICK, deleteMissileOnClick);
private function deleteMissileOnClick(e:MouseEvent):void {
e.currentTarget.visible = false;
//or any tween.
}
This removes the missile on the stage wherever it is when you click on the missile itself.
-
Ok so I succefully made what I wanted to.
And your command is working fine. But it only make it invisible, not delete it. I really want to delete it and for some reasons removechild isn't working.
I'm directly editing my missile AS file, what should I do to make it understand to delete the physical objet that is in the "real" game ?
why "this.removeChild();" isn't working while "this.visible = false;" works fine ?
-
This means the object itself. So when you are having a MovieClip, and you are inside the MovieClip, you can call it by using this. In the "root" of your application, this means the program itself.
The difference between your statement is that removeChild expects a value between the parentheses (the object you want to remove). By doing it your way nothing is removed. When you are doing obj.removeChild(obj2); You are removing an object inside another object (like an object in a holder). The visible method works fine because visible is just a property of the Sprite class, assuming "this" is a Sprite.
So what you'll do is just removing the current object the user is clicking:
Actionscript Code:
removeChild(e.currentTarget);
Good luck!
-
Actionscript Code:
if (DistanceSM >= DistanceSS) { //this.visible = false; removeChild(e.currentTarget); }
This is my current code for what you told me. It's not working, telling me that "e" is not defined. The rest of the code is working, proved by the fact that the visible command works (but disable here).
Any idea ?
-
You want to delete your missiles on Click, am I right? In the mouseClick function, you can use e.currentTarget. You can't use it outside the function.
-
No. In fact, I want the missile to explose on mouse location.
When distance Silo-Missile >= DistanceSilo-Mouse ("Souris" in French, that why "DistanceSS") the missile is removed with an eplosion effect.
Last edited by Gnougnou; 06-08-2012 at 10:20 AM.
-
I finally found out what I was looking for.
The command was :
Actionscript Code:
this.parent.removeChild(this);
What I was trying was :
Well, problem solved ! I post this in case it can help someone else
Thanks anyway !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|