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 649359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:56:08+00:00 2026-05-13T21:56:08+00:00

I’m setting up a class of public static vars that are to be BitmapData.

  • 0

I’m setting up a class of public static vars that are to be BitmapData.

The problem I’m having is I can’t seem to reference the vars dynamically in an array, making it impossible to give them values without some serious procdedural style coding.

This is what it looks like

package com.myPackage{

  import flash.display.*;
  import flash.events.*;
  import flash.net.*;

    public class Images extends Sprite{

       private var url1:String = "http://www.mydomain.com/myImage.jpg";
       private var url2:String = "http://www.mydomain.com/myImage2.jpg";

       public static var IMAGE_ONE_BDATA:BitmapData;
       public static var IMAGE_TWO_BDATA:BitmapData;

       private var urlArray = new Array(url1,url2);
       private var bDataArray = new Array(IMAGE_ONE_BDATA, IMAGE_TWO_BDATA);
       private var count:int = 0;

       public function Images(){
         initLoader();
       }

       private function initLoader():void
       {
          if(count < urlArray.length){
            var url:String = urlArray[count];
            var loader:Loader = new Loader();
            loader.load(new URLRequest(url));
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function (e:Event):void{
            bDataArray[count] = e.target.content.bitmapData;
            trace(IMAGE_ONE_BDATA) // <-- this should trace ([object-bitmapdata]) but instead returns null.. this is where I have to make a direct reference like..
            IMAGE_ONE_BDATA = e.target.content.bitmapData;
            trace(IMAGE_ONE_BDATA) // <-- will now return my bitmapdata object

            count++;
            initLoader();
           }else{
            dispatchEvent(new ImagesLoadedEvent);
       }
    }
 }  

Should I assume it’s because my array is a private var and placing references to public static vars is illegal? Is somebody gonna call the flash police on me?
Any input highly appreciated.

-Jascha

  • 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-13T21:56:09+00:00Added an answer on May 13, 2026 at 9:56 pm

    You’re slightly mis-understanding what the variables are. They are not objects, they are references to objects.

    Let me try to explain by walking you through your code:

    So, these two variables are local only to the Images instance, and reference the two strings you defined:

    private var url1:String = "http://www.mydomain.com/myImage.jpg";
    private var url2:String = "http://www.mydomain.com/myImage2.jpg";
    

    Now you define two variables, but you don’t assign them any values, so for the moment they are empty, or in AS3 “null”:

    public static var IMAGE_ONE_BDATA:BitmapData;
    public static var IMAGE_TWO_BDATA:BitmapData;
    

    Now you create a new array and pass into it the two objects referenced by url1 and url2. Note that you are not storing the two variables, you are storing the objects referenced by those variables. More of that in a minute:

    private var urlArray = new Array(url1,url2);
    

    so now, if you change url1 to “hello url1” and trace urlArray, you’ll still have the two urls in the array.

    If all that makes sense, then hopefully you can see what will happen here:

    private var bDataArray = new Array(IMAGE_ONE_BDATA, IMAGE_TWO_BDATA);
    

    you haven’t attached any objects to IMAGE_ONE_BDATA or IMAGE_TWO_BDATA; they are still null, so you’re passing null into the array twice. Later, if you assign an object to IMAGE_ONE_BDATA you haven’t assigned it to the array, just to that variable.

    Now you’ve assigned the bitmapdata to the array, but not to IMAGE_ONE_BDATA. Your expectations are wrong, it should return null:

        bDataArray[count] = e.target.content.bitmapData;
        trace(IMAGE_ONE_BDATA) // <-- this _should_ trace null
    

    Next you do reference the bitmapData to IMAGE_ONE_BDATA, so now it does have a reference

         IMAGE_ONE_BDATA = e.target.content.bitmapData;
         trace(IMAGE_ONE_BDATA) // <-- will now return my bitmapdata object
    

    The mistake is to think of IMAGE_ONE_BDATA as an object into which you put the bitmapData rather than as a name on a post-it note that you stick onto objects when you want to keep track of them. The bitmap-data itself is the object you’re interested in, not the name.

    If you need your bitmap-data to be public and static, forget your IMAGE_ONE_BDATA and IMAGE_TWO_BDATA and define:

    public static var bDataArray:Array
    

    instead.

    Hope this helps – no Flash police. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 366k
  • Answers 366k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer import datetime start = datetime.datetime(2009, 1, 31) end = datetime.datetime(2009,… May 14, 2026 at 4:41 pm
  • Editorial Team
    Editorial Team added an answer They should be able to simply allow emails from your… May 14, 2026 at 4:41 pm
  • Editorial Team
    Editorial Team added an answer Yes, use the Uri class in the System namespace: Uri… May 14, 2026 at 4:41 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.