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

Error with BitmapData.hitTest

New Here ,
Apr 28, 2014 Apr 28, 2014

I'm trying to better understand BitmapData.hitTest function so I went to :

http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000794.html

and pasted the example code into flash pro cc frame 1.

*****************************************

import flash.display.BitmapData;

import flash.geom.Point;

var myBitmapData:BitmapData = new BitmapData(100, 80, false, 0x00CCCCCC);

var mc_1:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());

mc_1.attachBitmap(myBitmapData, this.getNextHighestDepth());

var mc_2:MovieClip = createRectangle(20, 20, 0xFF0000);

var destPoint:Point = new Point(myBitmapData.rectangle.x, myBitmapData.rectangle.y);

var currPoint:Point = new Point();

mc_1.onEnterFrame = function() {

    currPoint.x = mc_2._x;

    currPoint.y = mc_2._y;

    if(myBitmapData.hitTest(destPoint, 255, currPoint)) {

        trace(">> Collision at x:" + currPoint.x + " and y:" + currPoint.y);

    }

}

mc_2.startDrag(true);

function createRectangle(width:Number, height:Number, color:Number):MovieClip {

    var depth:Number = this.getNextHighestDepth();

    var mc:MovieClip = this.createEmptyMovieClip("mc_" + depth, depth);

    mc.beginFill(color);

    mc.lineTo(0, height);

    mc.lineTo(width, height);

    mc.lineTo(width, 0);

    mc.lineTo(0, 0);

    return mc;

}

*************************************

I get the following error:

Scene 1, Layer 'Layer 1', Frame 1, Line 11, Column 461119: Access of possibly undefined property rectangle through a reference with static type flash.display:BitmapData.

Do I need to setup a property of some sort for this to run?

TOPICS
ActionScript
246
Translate
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 ,
Apr 28, 2014 Apr 28, 2014

You appear to be using Actionscript 2 and possibly a mix of Actionscript 2 and 3.  If you are trying to compile this as an Actionscript 3 file it won't work.

Translate
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 ,
Apr 28, 2014 Apr 28, 2014

Wow, your right, this was an AS2 help page. Thanks Ned.

Translate
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 ,
Apr 28, 2014 Apr 28, 2014
LATEST

You're welcome Kyle

Translate
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