Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlxG.as line 738,743 undefined property bitmapData #15

Closed
FlixelCommunityBot opened this issue Sep 13, 2012 · 10 comments
Closed

FlxG.as line 738,743 undefined property bitmapData #15

FlixelCommunityBot opened this issue Sep 13, 2012 · 10 comments
Assignees
Labels
Milestone

Comments

@FlixelCommunityBot
Copy link

Issue #217 by: kreso22

My editor caught it (Access of undefined property bitmapData)

        _cache[Key] = (new Graphic).bitmapData;
            if(Reverse)
                needReverse = true;
        }
        var pixels:BitmapData = _cache[Key];
        if(!needReverse && Reverse && (pixels.width == (new Graphic).bitmapData.width))
@FlixelCommunityBot
Copy link
Author

Comment by: IQAndreas

The "Graphic" you pass in should be a Class that extends Bitmap (NOT ByteArray or BitmapData).

What does your code look like?

@moly
Copy link
Member

moly commented Sep 23, 2012

There should be a more descriptive error message if the user passes in an invalid class. It might also be better to have the function return the default graphic rather than throwing an exception. I'm thinking something like:

if(!checkBitmapCache(Key))
{
    var bitmap:Bitmap = new Graphic() as Bitmap;
    if(bitmap == null)
    {
        FlxG.log("Error: " + Graphic + " must extend flash.display.Bitmap.");
        return FlxG.addBitmap(FlxSprite.ImgDefault);
    }
    _cache[key] = bitmap.bitmapData;
}

@IQAndreas
Copy link
Member

There should be a more descriptive error message if the user passes in an invalid class.

Good idea!

"Error: " + Graphic + " must extend flash.display.Bitmap."

Of course, with the old code, you could pass in any class as long as it has a bitmapData property. It didn't have to be a Bitmap. There could be cases where this could come in handy, such as if the BitmapData is generated rather than loaded through a Loader.

Though, in such a case, it may be better adding another method named addBitmapData where you can explicitly pass in the BitmapData instance rather than a class.

@Dovyski
Copy link
Member

Dovyski commented Sep 26, 2012

I liked the warning message @moly suggested. About the the bitmapData property @IQAndreas said, I agree it might be better idea to create a method named addBitmapData() to explicity pass in the BitmapData rather than a class.

@ghost ghost assigned Dovyski Oct 11, 2012
@IQAndreas
Copy link
Member

@Dovyski I noticed you were assigned to this issue. Do you already have the code ready for this fix, or shall I write some up and add the pull request?

I think we should separate off adding the error message in this release, and adding the addBitmapData() function to the next release.

@ghost ghost assigned IQAndreas Dec 20, 2012
@Dovyski
Copy link
Member

Dovyski commented Dec 20, 2012

I am sorry, I assigned this issue to me but stopped working when I noticed there would be some conflicts during the merge. I did nothing so far, @IQAndreas , so feel free to implement what was discussed. Bare in mind there are some pending pull requests that affect that very area of the code.

I agree with you about the error message and the new method. Leave addBitmapData() for the next release.

@IQAndreas
Copy link
Member

I assigned this issue to me but stopped working when I noticed there would be some conflicts during the merge.

It seems that all pull requests that modify FlxG have been merged by now, so I'll go ahead and add a pull request for this one.

@IQAndreas
Copy link
Member

I made two additional tweaks in the pull requst:

  • Added getClassName to make the log ouput clearer
  • Passed along the "reverse" parameter to the "default image" sprite. I think it might make a difference?

@Dovyski
Copy link
Member

Dovyski commented Dec 27, 2012

The getClassName() will be really useful.

About the "reverse", I can't tell if that makes any difference. In the context of the fix, the default image is just a "placeholder", so it's not that important to reverse it or not.

@IQAndreas
Copy link
Member

Resolved by 58f1e1f

IQAndreas added a commit to IQAndreas-testprojects/IQAndreas-flixel that referenced this issue Nov 15, 2013
Resolves the following issue:
 * FlxG.as line 738,743 undefined property bitmapData
   - FlixelCommunity#15
   - AdamAtomic#217
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants