Starling无法访问null对象引用的属性或方法

时间:2015-09-05 21:43:03

标签: actionscript-3 assets starling-framework

嘿,任何帮助表示感谢我被资产经理困扰了几天 这是我的夏威夷课程,我正在尝试从我的资产管理器类(MapAssetLoadQeue)引用资产。我得到了无法访问空对象引用的属性或方法。错误,如果我没有(Null)资产管理器引用,我的夏威夷类中会抛出错误,并且它会在我的Loader类中引发haw.showHawaii()

感谢!!!

package Maps
{
import flash.filesystem.File;

import Enqueue.MapAssetLoadQeue;

import starling.animation.IAnimatable;
import starling.animation.Juggler;
import starling.core.Starling;
import starling.display.Image;
import starling.display.MovieClip;
import starling.display.Sprite;
import starling.events.Event;
import starling.textures.Texture;
import starling.textures.TextureAtlas;
import starling.utils.AssetManager;

public class Hawaii extends Sprite
{
    public var mal:MapAssetLoadQeue = new MapAssetLoadQeue;
    public var Ocean:Image;






    public function Hawaii():void{
        super();
        this.addEventListener   
                      (starling.events.Event.ADDED_TO_STAGE, showHawaii);
    }



    public function showHawaii(e:Event):void{



        if(mal.mapAssets != null) {

     Ocean = new Image(mal.mapAssets.getTexture("blue"));
     addChild(Ocean);
    Ocean.x = 0;
    Ocean.y = 0;
        }
    }

这是我的加载器类,我加载了我的资产,这是我收到错误的地方。 haw.showHawaii(null)函数。无法访问null对象引用的属性或方法。

package Assets {
import flash.filesystem.File;

import Enqueue.MapAssetLoadQeue;

import GUI.Wave;

import Maps.Hawaii;

import starling.animation.IAnimatable;
import starling.animation.Juggler;
import starling.core.Starling;
import starling.core.starling_internal;
import starling.display.Image;
import starling.display.MovieClip;
import starling.display.Sprite;
import starling.events.Event;
import starling.textures.Texture;
import starling.textures.TextureAtlas;
import starling.utils.AssetManager;


public class Loader extends Sprite {

    var loadText: Texture = Texture.fromEmbeddedAsset(loadMCTexture);
    var loadXml: XML = XML(new loadMC0Xml());
    var loaderAtlas: TextureAtlas = new TextureAtlas(loadText, loadXml);
    public var loaderMovie: MovieClip = new MovieClip(loaderAtlas.getTextures("loading_"));
    public var mal: MapAssetLoadQeue = new MapAssetLoadQeue;
    public var wave:Wave = new Wave;
    public var haw:Hawaii;





    //Loader MovieClip size 720X233;
    [Embed(source = "/../Wavehunter/loadScreenAssets/wm/MovieClips/loader/loader_0.xml", mimeType = "application/octet-stream")]
    public static const loadMC0Xml: Class;

    [Embed(source = "/../Wavehunter/loadScreenAssets/wm/MovieClips/loader/loader_0.png")]
    public static const loadMCTexture: Class;


    // public var juggler:Juggler = Starling.juggler;
    /*
    ======================================================================
    Every Movieclip asset for the worldMap
    > Load WorldMap Assets on stage as Png and Make all alpha to 30%
    > and within each function make that png invible to false or remove
    > add MoviClip over the invisible png after load is processed
    =======================================================================
    */







    // Load WorldMap asset function
    public function mapLoader(): void {
        mal.requestWM();
        addChild(loaderMovie);
        loaderMovie.x = 347;
        loaderMovie.y = 277;
        loaderMovie.play();
        Starling.juggler.add(loaderMovie);
    }
    public function mapLdr(){
        loaderMovie.visible = true;
        addChild(loaderMovie);
        loaderMovie.x = 347;
        loaderMovie.y = 277;
        loaderMovie.play();
        Starling.juggler.add(loaderMovie);
    }
    //this function resizes the loader to original size and places at the bottom corner
    public function resizeLdr(){
        loaderMovie.width = 72;
        loaderMovie.height = 22;
        loaderMovie.x =1237;
        loaderMovie.y = 712;
    }

    public function callLoad(): void {



    public function callHawaii(): void {
        trace(" Hawaii is being runned");
        //mal.mapAssets.verbose = true;

        mal.mapAssets.loadQueue(function onGo(ratio: Number): void {

            trace("Hawaii percentage is", ratio);
            if (ratio == 1.0) {
                Starling.juggler.delayCall(function (): void {
                    loaderMovie.visible = false;
                    //addChild(haw.Ocean);
                //  addChild(haw);
                    trace("this is haw value",haw);
                    //trace("this is the function", haw.showHawaii(null));
                    haw.showHawaii(null);

                }, 0.30);

            }
        });
    }









    public function showMap() {
        // get texture by name
        addChild(mal);
        mal.accesMap();
        mal.hawaii.addEventListener(Event.TRIGGERED,removeMap);


    }
    // this code removes the HawaiiMap from the screen and goes directly to the wave
    public function removeMap(){
        trace("function initated"); 
        mapLdr();
        resizeLdr();
        mal.mapAssets.purge();
        mal.requestHawaii();
        callHawaii();

            mal.hawaii.removeEventListener(Event.TRIGGERED,removeMap);


    }

    public function Loader() {
        super();
    }
}

}

这是我的资产经理课程

package Enqueue {
import flash.filesystem.File;
import Assets.MapAnimate;
import Assets.MapAssets;
import Maps.Hawaii;
import starling.animation.IAnimatable;
import starling.animation.Juggler;
import starling.animation.Transitions;
import starling.animation.Tween;
import starling.core.Starling;
import starling.core.starling_internal;
import starling.display.Button;
import starling.display.Image;
import starling.display.MovieClip;
import starling.display.Sprite;
import starling.events.EnterFrameEvent;
import starling.events.Event;
import starling.textures.Texture;
import starling.textures.TextureAtlas;
import starling.utils.AssetManager;




public class MapAssetLoadQeue extends Sprite {
    public var mapAssets: AssetManager;

    public function MapAssetLoadQeue() {
        super();
    }


    public function requestHawaii():void {
        //  mapAssets.verbose =false;
    //  mapAssets = new AssetManager;
        var appDir:File = File.applicationDirectory;
        mapAssets.enqueue(appDir.resolvePath("IslandMaps/Hawaii"));
        //mapAssets.enqueue(Hawaii);
        mapAssets.verbose = true;
    }

1 个答案:

答案 0 :(得分:1)

如果这是你的所有代码,如果我没有遗漏任何明显的东西,我不认为你在任何地方创造了“haw”。也就是说,你似乎没有像......这样的东西。

haw = new Hawaii();

......所以,它会是空的!