• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Doesn't work my addChild command on Class

New Here ,
Jun 16, 2012 Jun 16, 2012

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.

TOPICS
ActionScript

Views

933

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jun 16, 2012 Jun 16, 2012

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

...

Votes

Translate

Translate
LEGEND ,
Jun 16, 2012 Jun 16, 2012

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/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 16, 2012 Jun 16, 2012

Copy link to clipboard

Copied

Thank you for your quick response. I will try now, I wasted 2 days for these problem. If I can solve problem, I will write here

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 16, 2012 Jun 16, 2012

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 16, 2012 Jun 16, 2012

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);
                              }
                    }
          }
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 17, 2012 Jun 17, 2012

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 17, 2012 Jun 17, 2012

Copy link to clipboard

Copied

LATEST

You're welcome

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines