Skip navigation
he11f1re
Currently Being Moderated

Object follows mouse after clicked

Aug 23, 2011 3:25 PM

The title says what I want to achieve.

My code is this :

package
{
    import flash.display.*;
    import flash.events.*;
    public class Sample extends MovieClip {
        public function Sample():void {
            var c:Rreth = new Rreth  ;
            c.x = 275;
            c.y = 205;
            c.buttonMode = true;
            c.addEventListener(MouseEvent.MOUSE_DOWN,MouseDown);
            addChild(c);
        }
        public function MouseDown(e:MouseEvent):void {
            c.addEventListener(Event.ENTER_FRAME, moveMyRreth);
        }
        public function moveMyRreth(event:Event):void {
            var thisRreth:Rreth = (event.target as Rreth);
            thisRreth.x -=  thisRreth.x - mouseX;
            thisRreth.y -=  thisRreth.y - mouseY;
        }
    }
}

The error thrown is :

C:\Users\Adi\Desktop\Sample\Sample.as, Line 15    1120: Access of undefined property c.

Who can help me achieve the result I want ?

 
Replies
  • Currently Being Moderated
    Aug 23, 2011 3:31 PM   in reply to he11f1re

    The error is telling you. c is a undefined property. Try capitalise c.

    so :

     

    package
    {
        import flash.display.*;
        import flash.events.*;
        public class Sample extends MovieClip {
            public function Sample():void {
                var c:Rreth = new Rreth  ;
                C.x = 275;
                C.y = 205;
                C.buttonMode = true;
                C.addEventListener(MouseEvent.MOUSE_DOWN,MouseDown);
                addChild(C);
            }
            public function MouseDown(e:MouseEvent):void {
                C.addEventListener(Event.ENTER_FRAME, moveMyRreth);
            }
            public function moveMyRreth(event:Event):void {
                var thisRreth:Rreth = (event.target as Rreth);
                thisRreth.x -=  thisRreth.x - mouseX;
                thisRreth.y -=  thisRreth.y - mouseY;
            }
        }
    }

     

    I dont know what c is, if it is in the library look at it see exactly what you named it, AS3 is a case sensative language.

     

    It might be the case that you did not give the object a instance name

     

    If you did not give it a instance name, drag it onto the stage give it a instance then delete it.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 24, 2011 6:42 AM   in reply to he11f1re

    Your var c is defined within the function Sample therefore function MouseDown has no idea what c is. Define outside the function:

    ...
    private var c:Rreth;
     
    public class Sample extends MovieClip {
            public function Sample():void {
                c = new Rreth();
    ...
    
     
    |
    Mark as:
  • Currently Being Moderated
    Aug 24, 2011 7:55 AM   in reply to he11f1re

    Oops you're right - silly mistake

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points