Copy link to clipboard
Copied
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 ?
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();...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Rreth is the AS3 linkage for the movieclip on my library.
c is just a variable that copies the movieclip Rreth and displays it on stage after addChild() method.
It gives the same error even after changing c to C.
Copy link to clipboard
Copied
Anyone can help ...?
Copy link to clipboard
Copied
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();...
Copy link to clipboard
Copied
That's absolutely correct ..thanks.
I think you made a typo ...the private var must be made inside class
Copy link to clipboard
Copied
Oops you're right - silly mistake