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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:14:36+00:00 2026-06-04T23:14:36+00:00

I created a basic class to handle a task I knew I’d want to

  • 0

I created a basic class to handle a task I knew I’d want to do a lot over the course of some platformer being programmed in Flixel. The class was written in pure AS3, and meant to hold ongoing facilities to convert embedded files into various data types that took more than one step to do so.

package net.darkglass.conversion
{
import flash.display.BitmapData;
import flash.display.DisplayObject;

public class Embedded
{
    /**
     * Returns a BitmapData loaded with the given embedded image class.
     * 
     * This function does no real error checking.
     * 
     * TODO: Establish basic error checking for function.
     * 
     * @param image An embedded image class object
     * @return BitmapData loaded with contents of Image
     */
    public function imageToBitmapData(image:Class):BitmapData
    {
        // instantiate image as a DisplayObject
        var imageDisplayObject:DisplayObject = new image();

        // create empty BitmapData to use, using image's size for the BitmapData's size
        var imageBitmapData:BitmapData = new BitmapData(imageDisplayObject.width, imageDisplayObject.height);

        // load imageDisplayObject's contents into imageBitmapData
        imageBitmapData.draw(imageDisplayObject);

        // that should be all we need. Return imageBitmapData
        return imageBitmapData;
    }
}
}

I then, in my code, instantiated this object and proceeded in two slightly different ways to try to use it to generate a loaded BitmapData.

The first, which failed (seems to successfully create an empty BitmapData):

// ...
/* Our source image for the test map */
[Embed(source="../asset/graphic/debug/testmap.png")]
public var testmap:Class;
// ...
public var converter:Embedded;
// ...
// test level!
var testmapBD:BitmapData = converter.imageToBitmapData(testmap);

The second, which shows the same results as the first:

// ...
// Only the last few lines change...
// ...
// test level!
var testmapBD:BitmapData = new BitmapData(0, 0);
testmapBD = converter.imageToBitmapData(testmap);
// ...

It appears that AS3 doesn’t return the instantiated object? Or, apparently, anything usable? as a one-off, I went ahead and tried to change the BitmapData’s dimensions to the correct size from the second case, to no avail:

// ...
// Only the last few lines change...
// ...
// test level!
var testmapBD:BitmapData = new BitmapData(40, 30);
testmapBD = converter.imageToBitmapData(testmap);
// ...

Searching here and around a bit, I was under the impression that primitives are pass-by-value in AS3, and that complex-types are pass-by-reference… And I would assume (however unsafely) that BitmapData is a complex-type.

Is there a way to do this? What am I misunderstanding or missing here?

  • 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-04T23:14:37+00:00Added an answer on June 4, 2026 at 11:14 pm

    Far too often, my worst problems in any code seem to be reducable to “did you initialize your objects properly?”

    I cannot manage to credit 32bitkid up above for the answer; however, his answer is the one that is correct given my own code and described problems. Simply initializing the Embedded object converter via converter = new Embedded() fixes the problem with no further change to my code. BitmapData objects can be initialized with the returned data and it behaves as I would suspect it would based on the notes from language spec before.

    However, both Amy Blankenship’s answer and Florian Salihovic’s answers are valuable as scraps of data and code. Amy Blankenship’s answer reveals a little data about the language and its behavior that took me a while to dig out to confirm; bringing such useful information directly to the surface is never bad. Florian’s answer is both interesting code (from the point of someone still learning) and useful for specific cases, no doubt.

    The best solution for me here, based on what I actually understand and what I was originally asking is simply “I’m an idiot and need to write a giant sign to hang on the wall opposite my work machine now that says INITIALIZE YOUR OBJECTS PROPERLY”. However, that is not to discredit or disparage the usefulness of other solutions offered.

    I do, however, want to turn in my license to hack code together after this. This is the second time on record that my only real problem is not initializing properly.

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

Sidebar

Related Questions

I have some basic (stupid) questions about AWS EC2 instances or AMIs. I created
I've created a singleton class that should handle all the data loading for my
I have created a custom even class which is pretty basic. But when calling
i want to create a basic game Draw engine class for my 2D game.
I have some code below. This code is a basic push/pop stack class that
I have a Rails 3.2.2 application using Ruby version 1.9.2. I have created basic
I created a basic calculator service called MiniCalc that only has two operations. Add
I have created a basic site using ASP.NET routing according to Mike Ormond's example
I've created this basic 3D Demo using OpenGL/SDL. I handled the keyboard callback so
I created a site template from a basic site which was itself created from

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.