1

I am a newbie to AS3. I have a movie clip.I want to know if there is a drawing/graphic drawn over movie clip at all?

deepankardixit90
  • 351
  • 4
  • 19

3 Answers3

0

Simple, check the width and height of the MovieClip. Assuming you mean the MovieClip itself contains the drawing/graphic.

After seeing Fygo's comment

I did some testing and found out that the scale properties of the MovieClip will change depending on whether or not it has any graphics.

Meaning if you set the width and height to zero, the corresponding scaleX and scaleY will also be set to zero. So what you can do is check the scale AND the dimensions of the MovieClip. If both scales are 1:1 and both dimensions are 0:0, that means you didn't mess with the dimensions and it truly is graphic-less.

trace (awd.scaleX, awd.scaleY, awd.width, awd.height);
//If you get 1 1 0 0 as the output, the MovieClip is empty
TreeTree
  • 3,200
  • 3
  • 27
  • 39
  • 1
    It is much more complicated than that. You can set height/width to 0 and even then the MC can have content. That you could easily check with mc.numChildren > 0 tho. But mc.graphics... that's more difficult. I assume you could draw it into a bitmap, and check every pixel manually whether it is transparent. – Fygo Apr 09 '14 at 15:11
  • scaleX and scaleY properties has nothing to do with graphics, they are being read while drawing and not written by the graphics. So they always be the same, except if the programmer decides to change the scaling. :) – Zhafur Apr 09 '14 at 20:55
  • scaleX and scaleY are related to width and height. If you change the width to half, scaleX will automatically be changed to 0.5. If you set both scales to 1 then you essentially set the MovieClip to its "initial" state, that is the programmer did not deliberately set its width and height to 0. If you then check the width and height, you'll know if there is any graphics in it. – TreeTree Apr 09 '14 at 21:28
0

Use readGraphicsData(). I assume that if it's empty it means there is nothing drawn there :)

It's not perfect though, read the reference

Andrey Popov
  • 7,362
  • 4
  • 38
  • 58
  • Ya I had seen that but one problem with this API is that it was introduced with FP 11.6. I don't think its going to run in FF running on Linux based OS as the last update to FP was 11.2. – deepankardixit90 Apr 10 '14 at 05:07
  • March 12th, 2013. Welcome to Flash Player 11.6. I think you are somehow wrong :) – Andrey Popov Apr 10 '14 at 07:38
  • From Adobe website --- Mozilla, Firefox, SeaMonkey (Flash Player 11.2 is the last supported Flash Player version for Linux. Adobe will continue to provide security updates.) – deepankardixit90 Apr 10 '14 at 13:24
  • Sorry, my bad I missed 'Linux'. Hm, well I guess the best practice is just to know if you draw something or not, via simple bool :D – Andrey Popov Apr 10 '14 at 13:44
  • Actually I have an eraser as well.If I draw I can set the bool to true.But if I erase and do it partially, what to set? I will never know when it is fully erased.So in a way I have to know if there is a graphic of a particular color drawn? – deepankardixit90 Apr 11 '14 at 05:14
  • Are you using bitmapdata for drawing and erasing? See **Kapep**'s answer to a similar question: [Link here](http://stackoverflow.com/questions/7282484/as3-how-to-check-if-bitmapdata-is-empty). The logic in that answer is that an empty bmpData object has 0 width/height but if it contains say one pixel it now has W and H of 1 pixel... As for your `hasDrawing` boolean. Set true from the first drawing click. If you part erase it still has part of a drawing, only should be false when fully erased all the pixels (via function: detect/check if no pixels and reset boolean). Hope it helps – VC.One Apr 11 '14 at 18:43
0

Maybe you just mean collision detection? To detect if two movieClips are touching...? For that you need either:

HitTestObject - (checks if two objects touching by their box boundaries) - Link:

or HitTestPoint - (read description carefully) - Link:

A good tutorial explaining both methods is here: - Link:

example code:

if ( MC_one.hitTestObject(MC_two) )
{
  trace("MovieClip One is touching/over MovieClip Two"); 
  //add code needed to happen when touching/over. example below
  //MC_two.gotoAndStop(2); //example tells touched MC_two to change frame to 2
}
VC.One
  • 14,790
  • 4
  • 25
  • 57
  • No I never meant that. – deepankardixit90 Apr 11 '14 at 04:27
  • Yeah I realised after I posted that I misread "on a movieclip" as meaning "upon" not "within" (ie: touching).. Anyways from the comments it sounds like you're actually using bitmapdata? Your question should be "How to detect if there is pixels drawn on a bitmapData in AS3?" The movieclip is irrelevant bcos its just a container and asking about that leads to answers not helpful for your bmpData situation.. – VC.One Apr 11 '14 at 18:38