LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 




 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-01-2008, 08:57 AM
Maniky80 Maniky80 is offline
Registered User
 
Join Date: Oct 2008
Posts: 5
Rep Power: 0
Maniky80 is on a distinguished road
Exclamation Class Instances (MovieClips) that do not respond to an IF (hitTestObject) statement

I've created a Bullet.as class that contains the following code:

Actionscript:
package {

    import flash.display.MovieClip;
    import flash.events.Event;

    public class Bullet extends MovieClip {

        private var speedX:Number=10;
        private var pozX:Number;
        private var pozY:Number;

        function Bullet(pozX, pozY):void {
            this.x = pozX;
            this.y = pozY;
            this.addEventListener(Event.ENTER_FRAME,moveBullet);

        }
        public function moveBullet(evtBullet:Event):void {

            evtBullet.target.x+= speedX;

            if (evtBullet.target.x > stage.stageWidth - evtBullet.target.width / 2 || evtBullet.target.x < evtBullet.target.height / 2) {
                speedX=- speedX;
            }
        }
        
        public function stopBullet():void {
            this.removeEventListener(Event.ENTER_FRAME, moveBullet);
        }

    }
}
And I linked my class to the movie clip object in my library via the LINKAGE option.

My main FLA file contains this code:

Code:
var newBullet:Bullet = new Bullet(10,200);
addChild(newBullet);

var newBullet2:Bullet = new Bullet(200,200);
addChild(newBullet2);

if (newBullet.hitTestObject(newBullet2)) {
    trace("HIT");
    newBullet.stopBullet();
    newBullet2.stopBullet();
}
Ca someone explain to me why the IF statement is not working if these to objects (bullets) collide?
I must say the I've noticed that IF statement works if these two objects are not moving but they intersect each other.
What am I doing wrong here? Thank you.
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
using class with movieclips in another project skitzer Flash CS3 / Flash 9 1 04-20-2010 01:23 PM
Objects, Classes, Instances, and Scope MedievalFlash Newbies 9 01-21-2008 01:15 PM
Creating instances of one class in another class silentbob Actionscript 2.0 3 12-05-2005 09:35 AM
Question about movieClips with external class files Krel3 Flash MX 2004 1 09-22-2005 02:53 PM
as2 class questions Solari Flash MX 2004 7 10-11-2003 01:38 AM




All times are GMT. The time now is 05:28 PM.