Skip to main content
Inspiring
May 7, 2020
Question

TypeError: Error #1006: myDCLS is not a function.

  • May 7, 2020
  • 1 reply
  • 1420 views

I'm trying to access function located in DCLS class from my Pieces class.

Pieces:

  public class Piece extends Sprite
   {
      private var image:Bitmap; 
      private var obj:Object;
      private var gap:Number = 30;  
    
      public function Piece()
      {
         super();
      }
      
      public function init($obj:Object) : void
      {
        this.obj = $obj;
        //taking valuse from my DCLS class works fine
	totalPieces = this.obj.horizontalPieces * this.obj.verticalPieces;
	//here I'm getting error #1006
        this.obj.myDCLS(); 
        

myDCLS function located in DCLS class:

	  public function myDCLS(){
		  //var mycount:int = count;
		  //foundPiecesDCLS++;
		  trace("test");
	  }
This topic has been closed for replies.

1 reply

JoãoCésar17023019
Community Expert
Community Expert
May 7, 2020

Hi.

 

How are you calling the init method?

SwyzeAuthor
Inspiring
May 7, 2020

I do it like that:

pieceGuid = new Piece();
                  showGuidCon.addChild(pieceGuid);
                  pieceGuid.init({
                     "image":nowbitmap.bitmapData,
                     "i":i,
                     "j":j,
                     "tileObj":piecesArray[i][j],
                     "horizontalPieces":horizontalPieces,
                     "verticalPieces":verticalPieces,
					  "foundPiecesDCLS":foundPiecesDCLS,
                     "crop":{
                        "x":i * pieceWidth,
                        "y":j * pieceHeight,
                        "width":pieceWidth,
                        "height":pieceHeight
                     },
                     "x":i * pieceWidth + i,
                     "y":j * pieceHeight + j,
                     "width":pieceWidth,
                     "height":pieceHeight,
                     "draggable":false
                  });
JoãoCésar17023019
Community Expert
Community Expert
May 7, 2020

Thanks.

 

You need to pass an instance of the DCLS class to the init method object you're using as an argument. Something like this:

pieceGuid.init({dLCSInstance:yourDLCSInstance});

// ...

this.obj.dLCSInstance.myDCLS();

 

Or if you don't want/need to instantiate the DCLS class, mark the myDCLS method as static. Like this:

public static function myDCLS():void
{
}

 

Then call the myDCLS method like this:

DCLS.myDCLS();