1

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() ?

khomyakoshka
  • 1,259
  • 8
  • 18
karthick
  • 11,998
  • 6
  • 56
  • 88
  • How did you load the SWF? Did you use custom ActionScript 3 code, or an LFC API? – raju-bitter Sep 11 '12 at 08:29
  • @RajuBitter: Using LFC only. view.setSource().. – karthick Sep 11 '12 at 08:38
  • 2
    Functions like the [LaszloView.setSource()](http://svn.openlaszlo.org/openlaszlo/trunk/WEB-INF/lps/lfc/views/LaszloView.lzs) functions are mostly wrappers calling the runtime specific implementation of the sprite object. If you want to find out which ActionScript code is being called, you can always look at the [SWF9 kernel source](http://svn.openlaszlo.org/openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as) directly. – raju-bitter Sep 11 '12 at 10:22

1 Answers1

1

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.

raju-bitter
  • 8,906
  • 4
  • 42
  • 53