Copy link to clipboard
Copied
My project running without problem, but when I'm click my object in the stage, I'm taking "TypeError: Error #1009: Cannot access a property or method." error. Here my project https://rapidshare.com/files/1556610915/Proje.rar
my code in fla:
import Gosterge;
var gosterg:Gosterge = new Gosterge();
gosterg.gostergeleriEkle(a,c,k1);
my code in Gosterge.as:
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class Gosterge extends Sprite
{
public var cerceve:Sprite = new Sprite ;
public function Gosterge():void
{
// constructor code
}
private function tikla(evt:MouseEvent):void
{
trace("tikla çalıştı");
cerceve.graphics.lineStyle(1, 0x0000FF, 1);
cerceve.graphics.lineTo(100,0);
cerceve.graphics.lineTo(100,100);
cerceve.graphics.lineTo(0,100);
cerceve.graphics.lineTo(0,0);
cerceve.x = evt.currentTarget.x - 5;
cerceve.y = evt.currentTarget.y - 5;
stage.addChild(cerceve);
}
public function gostergeleriEkle(... args):void
{
for (var i:uint = 0; i < args.length; i++)
{
args.addEventListener(MouseEvent.CLICK, tikla);
}
}
}
}
Please help, I can't find problem.
Will itsolve your problem if you pass the stage to the function as an argument. Since the class is not added to the stage, then it probably needs to be provided a reference to it. See the bolded changes/additions to the code below...
import Gosterge;
var gosterg:Gosterge = new Gosterge();
gosterg.gostergeleriEkle(this.stage,a,c,k1);
package
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.MouseEvent;
public class Gosterge extends
...Copy link to clipboard
Copied
Chances are the stage is not a defined entity for the class. You might need to add an event listener for ADDED_TO_STAGE wherein the event handler establishes the stage for the class. See if the following tutorial helps solve anything, and if niot, try searching Google using "AS3 ADDED_TO_STAGE"
http://www.emanueleferonato.com/2009/12/03/understand-added_to_stage-event/
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I tried your advice, but I can't solve problem. Can you edit my project? if you help me, I would greatful.
Copy link to clipboard
Copied
Will itsolve your problem if you pass the stage to the function as an argument. Since the class is not added to the stage, then it probably needs to be provided a reference to it. See the bolded changes/additions to the code below...
import Gosterge;
var gosterg:Gosterge = new Gosterge();
gosterg.gostergeleriEkle(this.stage,a,c,k1);
package
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.MouseEvent;
public class Gosterge extends Sprite
{
public var cerceve:Sprite = new Sprite ;
public var _stage;
public function Gosterge():void
{
// constructor code
}
private function tikla(evt:MouseEvent):void
{
trace("tikla çalıştı");
cerceve.graphics.lineStyle(1, 0x0000FF, 1);
cerceve.graphics.lineTo(100,0);
cerceve.graphics.lineTo(100,100);
cerceve.graphics.lineTo(0,100);
cerceve.graphics.lineTo(0,0);
cerceve.x = evt.currentTarget.x - 5;
cerceve.y = evt.currentTarget.y - 5;
_stage.addChild(cerceve);
}
public function gostergeleriEkle(stag:Stage,... args):void
{
_stage = args[0];
for (var i:uint = 1; i < args.length; i++)
{
args.addEventListener(MouseEvent.CLICK, tikla);
}
}
}
}
Copy link to clipboard
Copied
Thank you very much, thank you very much, really thank you very much , I finally understood. It works now . My class couldn't reach the stage. Mr. Ned, you're the best , I'm so grateful
Copy link to clipboard
Copied
You're welcome