Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8773121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:12:52+00:00 2026-06-13T18:12:52+00:00

I am making a tool which obscures an image with squares. What I want

  • 0

I am making a tool which obscures an image with squares. What I want to happen is to have a bouncing ball which hits the squares and makes them disappear. However, the removeChild command isn’t working right. I set it up to populate the image with empty movie clips and colorize them. However, when I click the square, I am running into problems with the parent/child. I keep running into this error. “The supplied DisplayObject must be a child of the caller.” I cannot think of a good way to assign the eventListeners to each individual squares. I’m sure it is obvious. Here is my code. Thank you in advance

EDIT:If I get it to work, it deletes all instances of the square, not just the one I clicked.

Here is my code

 var mc:MovieClip = bgIMG;
 var bd:BitmapData = new BitmapData(mc.width,mc.height);
 bd.draw(mc);

 var _img:Bitmap = new Bitmap(bd);
 var _imgNodes:Array = [];
 var _tiledImg:MovieClip = container_tiled_img;

 var pad:int = 0;
 var rows:int = 10;
 var cols:int = 10;
 var zero:Point = new Point();

 createImgNodeGrid(rows, cols, pad);
 pixelateNodes(_imgNodes);



 function removeMC(e:MouseEvent)
 {//removes the movie clip
 trace(e.currentTarget.x);
stage.removeChild(e.currentTarget.parent.parent);
 }


 function pixelateNodes(nodes:Array = null):void
 {
for each (var node:Bitmap in nodes)
{
    node.bitmapData.fillRect(node.bitmapData.rect, avgColor(node.bitmapData));

}
 }

 function avgColor(src:BitmapData):uint
 {
var A:Number = 0;
var R:Number = 0;
var G:Number = 0;
var B:Number = 0;

var idx:Number = 0;
var px:Number;

for (var x:int = 0; x < src.width; x++)
{
    for (var y:int = 0; y < src.height; y++)
    {
        px = src.getPixel32(x,y);

        A +=  px >> 24 & 0xFF;
        R +=  px >> 16 & 0xFF;
        G +=  px >> 8 & 0xFF;
        B +=  px & 0xFF;

        idx++;
    }
}

A /=  idx;
R /=  idx;
G /=  idx;
B /=  idx;

return A << 24 | R << 16 | G << 8 | B;
 }


 function createImgNodeGrid(rows:int = 1, cols:int = 1, pad:Number = 0):void
 {
var w:Number = _img.width / rows;
var h:Number = _img.height / cols;
var numNodes:int = rows * cols;

_imgNodes = [];

var nodeCount:int = 0;
for (var i:int = 0; i < rows; i++)
{
    for (var j:int = 0; j < cols; j++)
    {
        // get area of current image node
        var sourceRect:Rectangle = new Rectangle(i * w, j * h, w, h);

        // copy bitmap data of current image node
        var tempBd:BitmapData = new BitmapData(w,h,true);
        tempBd.copyPixels(_img.bitmapData, sourceRect, zero);

        // place image node bitmap data into sprite
        var imgNode:Bitmap = new Bitmap(tempBd);
        imgNode.x = i * (w + pad);
        imgNode.y = j * (h + pad);

        // store each image node
        //_imgNodes.push(imgNode);
        _imgNodes[nodeCount++] = imgNode;

        // add each image node to the stage
        _tiledImg.addChild(imgNode);
        _tiledImg.addEventListener(MouseEvent.CLICK,removeMC);
    }
}
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:12:53+00:00Added an answer on June 13, 2026 at 6:12 pm

    The problem you have is your are adding the event to the parent of the node(_tiledImg).

    function createImgNodeGrid(rows:int = 1, cols:int = 1, pad:Number = 0):void
    {
      var w:Number = _img.width / rows;
      var h:Number = _img.height / cols;
      var numNodes:int = rows * cols;
    
      _imgNodes = [];
    
      var nodeCount:int = 0;
      for (var i:int = 0; i < rows; i++)
      {
        for (var j:int = 0; j < cols; j++)
        {
            // get area of current image node
            var sourceRect:Rectangle = new Rectangle(i * w, j * h, w, h);
    
            // copy bitmap data of current image node
            var tempBd:BitmapData = new BitmapData(w,h,true);
            tempBd.copyPixels(_img.bitmapData, sourceRect, zero);
    
            // place image node bitmap data into sprite
            var imgNode:Bitmap = new Bitmap(tempBd);
            imgNode.x = i * (w + pad);
            imgNode.y = j * (h + pad);
    
            // store each image node
            //_imgNodes.push(imgNode);
            _imgNodes[nodeCount++] = imgNode;
    
    
            // you need a container since you can not attach event listeners to a BitMap
            var sprite:Sprite = new Sprite()
            sprite.mouseChildren = false;
            sprite.addEventListener(MouseEvent.CLICK,removeMC);
            sprite.addChild(imgNode);
    
    
            // add each image node to the stage
            _tiledImg.addChild(sprite);
           // _tiledImg.addEventListener(MouseEvent.CLICK,removeMC);
        }
      }
    }
    
    function removeMC(e:MouseEvent)
    {
        var target:Sprite = event.currentTarget as Sprite;
        target.parent.removeChild(target)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a tool to track calls to house/senate reps, and I have 2
Let's say I'm making a tool to help epicureans keep track of which delicacies
I'm making a tool for a website thats under contruction that makes linkbuilding easier.
I'm making a tool, which can compare and list items. I'd like to animate
Hello I have a tool tip I am making with jquery, that loads the
I have a lot of jpeg images which I want to optimize for web
I am making an alert tool using web sql. I want to selects all
I have a Java application which draws a drawing. I want to give the
I am making a tool for web directory submission ,which will authomatically post to
I'm making a tool to dynamically display the sourcecode of running java class. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.