The purpose of the loader is to dynamically load resources. Click in the main toolbarButton to generate a loader.

Instance properties


The loader supports dynamic creation. The size of the loader must be set dynamically, otherwise it will not be displayed. E.g:

GLoader aLoader = new GLoader ();
    aLoader.SetSize (100,100);
    aLoader.url = "ui://package name/image name";

GLoader can load images, movieclips and components. If it is a resource in a UI package, it can be loaded by using the format of “ui://package name/image name”. But in actual projects, we may also need to load and display some images that are not in the UI package, which we call “external”. The default GLoader has a limited ability to load external resources. They are:


// AS3, load a network image
    aLoader.url = "http://www.fairygui.com/logo.png";
    // Egret, here demoRes is a resource defined in resources.json
    aLoader.url = "demoRes";
    // Unity, here is a texture with the path Assets / Resources / demo / aimage
    aLoader.url = "demo/aimage";

If these default external loading mechanisms cannot meet your needs, for example, you want to get resources from AssetBundle, or you need to add a cache mechanism (this is necessary, if you need to load repeatedly, it is recommended to cache), or you need to control the material Lifetime (this is also necessary because GLoader does not destroy externally loaded resources), then you need to extend GLoader.

  1. First write your Loader class. There are two important methods to override:
class MyGLoader: GLoader
      override protected function LoadExternal ()
          / *
          Start external loading, the address is in the url property
          Call OnExternalLoadSuccess after loading is complete
          Load failed call OnExternalLoadFailed
          Note: If it is external loading, after loading is finished, before calling OnExternalLoadSuccess or OnExternalLoadFailed,
          A more rigorous approach is to first check if the url attribute does not match the loaded content.
          If they do not match, the loader has been modified.
          In this case, you should give up calling OnExternalLoadSuccess or OnExternalLoadFailed.
          * /
      override protected function FreeExternal (NTexture texture)
          // Release externally loaded resources
  1. Register the Loader class we want to use. After registration is complete, in-gameAll loadersAll become instantiated by MyGLoader.

In the Unity platform, if you need to assign a Texture2D object to GLoader on some special occasions, such as a video map, you can do this:

// It must be noted that GLoader does not manage the life cycle of external objects and will not actively destroy your_Texture2D
  aLoader.texture = new NTexture (your_Texture2D);