Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe this is because you need to have a reference to the Background class before you can actually get the definition by name. Simply importing the Background class will not compile the class in to your swf, you need to reference it in some way. Creating an instance of the class is one way, however you can also reference the class after your import. </p> <p>try something like...</p> <pre><code>import com.somedomain.Background; Background; </code></pre> <p>This should create a reference to you class and ensure it is compiled in to your swf.</p> <p><strong>Edit to show multiple class usage.</strong></p> <p>If you have multiple background classes, I would recommend trying to make them adhere to an interface. I would then also create a background factory class that would allow you to create background instances from your configuration file. This also means that you would be able to put all your references to your background classes in the factory class. Here is what the factory could look like.</p> <pre><code>// let the compiler know we need these background classes import com.somedomain.backgrounds.*; DarkBackground; LightBackground; ImageBackground; class BackgroundFactory { public function create(type:String):Background { var bgClass:Class = getDefinitionByName(type) as Class; return new bgClass(); } } </code></pre> <p>Then to get a background instance from your config, you would do something like...</p> <pre><code>// parse your config file...not sure what format you've got it in. // instantiate a background factory and create an instance based on the name from your config. var bgFactory:BackgroundFactory = new BackgroundFactory(); var bg:Background = bgFactory.create(someStr); </code></pre> <p><strong>Edit to extend example</strong></p> <pre><code>package com.somedomain.background { interface Background { function get img():Bitmap; } } package com.somedomain.background { class SomeImageBackground extends Sprite implements Background { protected var _img:Bitmap; public function SomeImageBackground():void { _img = new SomeAssetFromLibrary(); } public function get img():Bitmap { return _img; } } } </code></pre> <p>Using these external classes would give you a bit more control over where the images come from. You could load them external, embed them using the embed meta data and even load them from the stage.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload