Copy link to clipboard
Copied
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");
}
Copy link to clipboard
Copied
Hi.
How are you calling the init method?
Copy link to clipboard
Copied
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
});
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
Static method does work, but now I'm getting undefined property or method errors (1180 and 1120 messages).
Copy link to clipboard
Copied
When I pass instance to the init method I get: mySwf.swf contains invalid data.
at DCLS()