Making Starling FrameWork to work with Classes that uses native DisplayObject
-
28-10-2019 - |
Pergunta
I'm trying to use Greensock LoaderMax on a Starling Framework project, but since Starling have a lots of its own class, how I can make it work with other classes that is using the native class?
Exp:
package
{
import flash.display.Sprite;
import flash.events.Event;
import starling.core.Starling
[SWF(width="1280",height="800",frameRate="60",backgroundColor="#002143")]
public class Main extends Sprite
{
private var mStarling:Starling
public function Main():void
{
mStarling = new Starling(Game, stage)
mStarling.antiAliasing = 1
mStarling.start()
}
}
}
package
{
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.ContentDisplay;
import com.greensock.loading.SWFLoader;
import starling.display.Sprite;
import starling.events.Event;
public class Game extends Sprite
{
private var queue:SWFLoader
private var mm:ContentDisplay
public function Game():void
{
if (stage)
init()
else
this.addEventListener(Event.ADDED_TO_STAGE, init)
}
private function init(e:Event = null):void
{
queue = new SWFLoader("MainMenu.swf", {onComplete: completeHandler})
queue.load()
}
private function completeHandler(e:LoaderEvent):void
{
mm = queue.content
addChild(mm)
}
}
}
will return the error:
Error: Implicit coercion of a value of type com.greensock.loading.display:ContentDisplay to an unrelated type starling.display:DisplayObject.
Solução
your MainMenu.swf
main class needs to extend starling.display.Sprite
since they are a different structure and etc... flash can not transform native sprite to starling sprite.
then after load complete:
mm = queue.content as Sprite; // ( starlig )
if you still want to use the normal DisplayObjects and Starling displayObjects, You need to place them in a different mc / sprites which extends different displayObjects.
stage
|...|
starling.display.Sprite -> Here you adding normal Starling Based Sprites / MovieClips
|...|
flash.display.Sprite -> here you adding native Sprites / MovieClips