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

  • Home
  • SEARCH
  • 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 531741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:19:57+00:00 2026-05-13T09:19:57+00:00

I am trying to copy the pixels of a bitmap data. but I keep

  • 0

I am trying to copy the pixels of a bitmap data. but I keep getting the following error

Parameter sourceBitmapData must be non-null.

it happens in the method drawImage. exact after my trace that says “got canvas data”.

 canvasData.copyPixels(image,tileRect,tilePoint);

Below is my code

package com.objects {

    import flash.display.Sprite;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.net.*;
    import flash.events.*;
    import flash.display.LoaderInfo;

    public class gameObject extends Sprite {

        protected var goWidth:Number;
        protected var goHeight:Number;
        protected var image:BitmapData;
        protected var canvas:Bitmap;

        public function gameObject():void
        {
            init();
        }

        private function init():void
        {

        }

        public function loadImage(imageDir:String):void
        {
            trace("loadimage");
            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE,imageComplete);
            loader.load(new URLRequest(imageDir));
        }

         private function imageComplete(e:Event):void {
            var loader:LoaderInfo = LoaderInfo(e.target);
            image = Bitmap(loader.content).bitmapData;
            trace("imagecomplete");
         }

         public function drawImage(xPoint:Number = 0, yPoint:Number = 0, tWidth:Number = 0, tHeight:Number = 0):void
         {
            var tilePoint:Point = new Point(0,0);
            var tileRect = new Rectangle(xPoint,yPoint,tWidth,tHeight);

            var canvasData:BitmapData = new BitmapData(tWidth,tHeight);
            trace("got canvas data");
            canvasData.copyPixels(image,tileRect,tilePoint);
            trace("copied pixels");
            canvas = new Bitmap(canvasData);
         }
    }
}

and below is what I use to call the class

balls = new Array();
            balls[0] = new gameObject();
            balls[0].loadImage("com/images/ball.gif");
            balls[0].drawImage(0,0,15,15);

Anyone have a clue ??

  • 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-05-13T09:19:57+00:00Added an answer on May 13, 2026 at 9:19 am

    Error occurs because the image variable (the first parameter to copyPixels) is null.

    The image variable of GameObject is populated in the imageComplete method that is called only when the loading is completed. loader.load() is asynchronous and returns before the image is fully loaded. You are calling drawImage () as soon as loadImage returns and hence image would be null at this time. Dispatch a complete event from the imageComplete method and wait for it before you call drawImage.

    private function imageComplete(e:Event):void 
    {
      var loader:LoaderInfo = LoaderInfo(e.target);
      image = Bitmap(loader.content).bitmapData;
      trace("imagecomplete");
      //dispatch a complete event.
      dispatchEvent(e);
    }
    
    game = new GameObject();
    //listen for the complete event
    game.addEventListener(Event.COMPLETE, handleComplete);
    game.loadImage("com/images/ball.gif");
    
    private function handleComplete(e:Event):void
    {
      //load complete and image populated : draw the image.
      var game:GameObject = GameObject(e.target);
      game.drawImage(0,0,15,15);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read in the pixel data from an image file as
When trying to copy a text file A to another file B, there may
im trying to copy 300 lines from one file to another, in source file
I'm trying to copy a file to another directory with Commons ' fileUtils. I
I am trying to copy contents of one xml file into another xml file.
I'm trying to copy my SQLite file that is used in my Air app
I am trying to copy over some files pulled out from a zip folder,
I'm trying to copy a file from one location to another using SHFileOperation: SHFILEOPSTRUCT
I need to get the byte array from my ColorConvertedBitmap representing the bitmap. I
I have a 2208 x 3000 TransformedBitmap object with format {Indexed8} that I'm do

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.