brenjt
brenjt

Reputation: 16297

As3 Static Method Call Internal Method

I downloaded a script from the internet and it works perfect. I started to adapt the code in it for a new application. But I get the following error 1061: Call to a possibly undefined method drawShape through a reference with static type Class.

When looking at the code I see that the method that is calling drawShape is a static method calling it as such: ShapeDrawer.drawShape(); Note that the ShapeDrawer class isn't being imported at all.

Then the drawShape method is as such: internal function drawShape() Can anyone explain to me why it may work in the application I downloaded and not mine. His was built for use with flash player 9 and mine is ten that may play a part.

This is what it looks like:

package puzzle
{
    import flash.geom.Point;    
    import utils.MyMath;

    public class PuzzleCaculater
    {
        public static function combineTwoPieces(pieceA:PuzzlePiece , pieceB:PuzzlePiece):void
        {
            for each(var drawingPiece in pieceB.unionPieces)
            {
                ShapeDrawer.drawShape(pieceA.graphicLayer , drawingPiece.shapeData , true);
                drawingPiece.disactive();
                drawingPiece.myGroup = pieceA.myGroup;
                drawingPiece.graphicLayer = pieceA.graphicLayer;
                pieceA.unionPieces.push(drawingPiece);
                drawingPiece.unionPieces = pieceA.unionPieces;
            }
        }
    }
}

package puzzle
{
    public class ShapeDrawer
    {
        internal function drawShape(target:Shape , drawingShapedata:Object , useBitmap:Boolean = true):void
        {
            var leftShape:Array= drawingShapedata.leftShape;
            var topShape:Array= drawingShapedata.topShape;
            var rightShape:Array= drawingShapedata.rightShape;
            var bottomShape:Array= drawingShapedata.bottomShape;
            var shapes:Array= [];
            shapes.push(leftShape);
            shapes.push(topShape);
            shapes.push(rightShape);
            shapes.push(bottomShape);
        }
    }
}

Upvotes: 0

Views: 2073

Answers (3)

You define drawShape like this:

internal function drawShape(...)

And you must define it like this:

static internal function drawShape(...)

Thath will fix your problem, the internal keyword isn't the problem (because both classes are in the same package)

Upvotes: 1

Bosworth99
Bosworth99

Reputation: 4234

Read up on access modifiers. They are critical to OO design patterns in AS3 (and other OO languages), and a misunderstanding of them will cause troubles ;)

Internal: The internal methods or properties are build to be shared across a common package. You need not to extend or inherit to the classes having Internal members(Where as we do inherit in case of protected) for accessing them. The internal members/methods are like public to the classes those are in same package

Declaring this method as Public will most likely fix your sitch... Cheers!

Upvotes: 0

Sam
Sam

Reputation: 1243

The internal keyword will prevent this function from being called outside of the package. Try making it public and see if that fixes it.

Upvotes: 0

Related Questions