Search code examples
migrationopenlaszlolzx

What is the equivalent of getMCRef().unloadMovie() in Openlaszlo 4.9


I want to know the equivalent of getMCRef().unloadMovie() in OL 4.9

I know that getDisplayObject() gives the display object will getDisplayObject.unload() similar to this getMCRef().unloadMovie() ?


Solution

  • The OpenLaszlo view class has an unload() function:

    view.unload(); Unloads media loaded with setSource or the source= attribute.

    <canvas>
    
      <view id="redBox" width="150" height="150">
        <method name="loadSWF">
           this.setSource('logo.swf');
        </method>
        <method name="unloadSWF">
           this.unload();
        </method>
      </view>
    
      <button x="200" text="Load SWF" onclick="redBox.loadSWF()"/>
    
      <button x="200" y="40" text="Unload SWF" onclick="redBox.unloadSWF()"/>
    
    </canvas>
    

    If you are interested in how resources are loaded, check the setSource function of the LzSprite.as SWF9 kernel file:

    /** setSource( String:url )
        o Loads and displays media from the specified url
        o Uses the resourceload callback method when the resource finishes loading 
    */
    public function setSource (url:String, cache:String = null, headers:String = null, filetype:String = null) :void {
        if (url == null || url == 'null') {
            return;
        }
        var loadurl:String = getLoadURL(url, cache, headers);
        if (getFileType(url, filetype) == "mp3") {
            // unload previous image-resource and sound-resource
            this.unload();
            this.__isinternalresource = false;
            this.resource = url;
            this.loadSound(loadurl);
        } else {
            if (this.isaudio) {
                // unload previous sound-resource
                this.unloadSound();
            }
    
            if (! imgLoader) {
                if (this.resourceContainer) {
                    // unload previous internal image-resource
                    this.unload();
                }
                imgLoader = new Loader();
                imgLoader.mouseEnabled = false;// @devnote: see LPP-7022
                imgLoader.mouseChildren = false;
                this.resourceContainer = imgLoader;
                this.addChildAt(imgLoader, IMGDEPTH);
                this.attachLoaderEvents(imgLoader.contentLoaderInfo);
            } else {
                //TODO [20080911 anba] cancel current load?
                // imgLoader.close();
            }
            this.__isinternalresource = false;
            this.resource = url;
            var res:Loader = this.imgLoader;
            if (res) {
                res.scaleX = res.scaleY = 1.0;
            }
    
            imgLoader.load(new URLRequest(loadurl), LzSprite.loaderContext);
        }
    }
    

    Within setSource(), an instance of the flash.display.Loader class is created: imgLoader = new Loader();

    Sometimes it's good to know which ActionScript classes are used internally in the LFC, since you can extend the functionality of OpenLaszlo - if needed.