Skip to content

Instantly share code, notes, and snippets.

@peterblazejewicz
Created June 10, 2011 09:08
Show Gist options
  • Save peterblazejewicz/1018522 to your computer and use it in GitHub Desktop.
Save peterblazejewicz/1018522 to your computer and use it in GitHub Desktop.
load local web page and local video into application using "file://" protocol converted paths
package
{
import flash.display.DisplayObject;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import mdm.Application;
import mdm.Browser;
import spark.components.Application;
import spark.components.Button;
import spark.components.VideoDisplay;
public class ExampleApplication extends Application
{
//
// gui related public variables
// also declared in mxml (mxml separation from as code)
//
public var loadWebPageButton:Button;
public var loadVideoButton:Button;
public var videoDisplay:VideoDisplay;
// reference to browser plugin
private var browser:mdm.Browser = null;
//
// button click handler to load web page into browser plugin
//
protected function loadWebPageHandler(event:MouseEvent):void
{
loadWebPageButton.enabled = false;
loadVideoButton.enabled = true;
callLater(loadWebPage);
};
//
// button click handler to load video into video display component
//
protected function loadVideoHandler(event:MouseEvent):void
{
loadWebPageButton.enabled = true;
loadVideoButton.enabled = false;
callLater(loadVideo);
};
//
// laods local web page
// hides video display instance
//
protected function loadWebPage():void
{
videoDisplay.source = undefined;
videoDisplay.visible = false;
//
var url:String = getPath("index.html");
if(browser != null)
{
browser.close();
browser = null;
}
var r:Rectangle = videoDisplay.getVisibleRect(this as DisplayObject);
browser = new mdm.Browser(r.x, r.y, r.width, r.height, url, false);
};
//
// loads video
// hides/closes browser instance
//
protected function loadVideo():void
{
if(browser)
{
browser.close();
browser = null;
};
videoDisplay.visible = true;
var url:String = getPath("video.mp4");
videoDisplay.source = url;
}
//
// util method convert relative path to full path
// only if required
//
private function getPath(path:String):String
{
if(mdm.Application.path && mdm.Application.path.length > 0)
{
path = "file://"+mdm.Application.path+path;
};
return path;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment