2

I have created hungryherogame (recreate) in adobe animate using starling framework.. download from this address below :

( http://www.test.farsvila.ir/animate_starling_Error.rar )

package {
    import flash.display3D.textures.Texture;
    import flash.utils.Dictionary;
    import flash.display.Bitmap;

    import starling.textures.Texture;
    import starling.display.Sprite;
    import starling.events.Event;
    import starling.display.Image;
    import starling.display.Button;
    import starling.core.Starling;
    import starling.events.Event;
    import screens.Welcome;

    public class Assets {

        [Embed(source = "media/graphics/bgWelcome.jpg")]
        public static const BgWelcome: Class;

        [Embed(source = "media/graphics/welcome_hero.png")]
        public static const WelcomeHero: Class;

        [Embed(source = "media/graphics/welcome_title.png")]
        public static const WelcomeTitle: Class;

        [Embed(source = "media/graphics/welcome_playButton.png")]
        public static const WelcomePlayBtn: Class;

        [Embed(source = "media/graphics/welcome_aboutButton.png")]
        public static const WelcomeAboutBtn: Class;

        private static var gameTextures: Dictionary = new Dictionary();

        public static function getTexture(name: String): Texture {
            if (gameTextures[name] == undefined) {
                var bitmap: Bitmap = new Assets[name]();
                gameTextures[name] = Texture.fromBitmap(bitmap);
            }
            return gameTextures[name];
        }
    }

}

Its made an error --> Call to a possibly undefined method fromBitmap through a reference with static type Class.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99

1 Answers1

2

in first look, every thing is OK! according DOC fromBitmap is a public static member of starling.textures.Texture

but problem is because of import flash.display3D.textures.Texture which is out of code block in your post and make me hanged some minutes !

so in this case, we have same class names, two Textures. compiler get mixed up too (Ambiguous reference Error).

try it

Edited

public static function getTexture(name: String): starling.textures.Texture {
    if (gameTextures[name] == undefined) {
        var bitmap: Bitmap = new Assets[name]();
        gameTextures[name] = starling.textures.Texture.fromBitmap(bitmap);
    }
    return gameTextures[name];
}

to make it clear for compiler, which Texture is your mean

Suggestion

i guess you don't really need import flash.display3D.textures.Texture; so remove it from your default code (problem solved without changing Texture to starling.textures.Texture)

payam_sbr
  • 1,428
  • 1
  • 15
  • 24