Technology Article

About Luster Packages

Luster supports the importing and attaching of external Luster applications to a running Luster application. The running Luster application may load and attach the new application using the stage:attachMovie function call.

Here is sample code:

function Root:LoadCore()
    trace("Loading VT_Core")
    local tempLoader = luster.net.Loader()
    tempLoader.dataFormat = "binary"
    local tempRequest = luster.net.URLRequest("../VT_Core/VT_Core.l3d.xml")--CommonData/l3d/VT_Core.l3d")
   
    tempLoader:addEventListener(luster.net.Loader.COMPLETE, Function(self, self.LoadCoreComplete))
    tempLoader:load(tempRequest)
end

-- Create self.core (the VT_Core object)
function Root:LoadCoreComplete(e)
    trace("Loaded VT_Core")
    local coreClass = stage:attachMovie(e.request.url, e.data, true)
    self.core = coreClass()
   
    -- Grab the SceneManager
    -- TODO: Organize this up a bit
   
    self.camera = luster.display.Camera()
   
    self.camera.z = 200
    trace(vt.SceneManager:Instance())
    self.sceneManager = vt.SceneManager:Instance()
    self.sceneManager:getScene():addChild(self.camera)
    stage:getViewport(0).camera = self.camera
   
   
   
   
    self:loadXml()
end

This code demonstrates the attaching of the external movie. It is first loaded using the luster.net.Loader class. Once the loaded event is called the code calls the attachMovie function. Note that the data must be binary form, whether or not the packaged l3d file format is used, or the development xml format is used. The return value from attachMovie is the root class from the attached movie, which you may then construct as any other class. This now gives you access to the loaded application. Once attached, the resources of the loaded movie are available in the original as if they were the original's resources.