Display HTML page in browser window upon clicking a button - html

I have a button on flex(AIR app). when i click on the button,has to open a browser window which will display an HTML page.

Create a URLRequest to the web page, and open it with navigateToURL :
var urlRequest:URLRequest = new URLRequest("http://www.adobe.com/");
navigateToURL(urlRequest);
Example loading a page upon click of a button with Flex MXML:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
import flash.net.navigateToURL;
protected function clickHandler(event:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.adobe.com"), "_blank");
}
]]>
</fx:Script>
<s:Button label="Open page"
click="clickHandler(event)" />
</s:Application>
navigateToURL():
Opens or replaces a window in the application that contains the Flash
Player container (usually a browser). In Adobe AIR, the function opens
a URL in the default system web browser.
Parameters
request:URLRequest — A URLRequest object that specifies the URL to navigate to.
For content running in Adobe AIR, when using the navigateToURL()
function, the runtime treats a URLRequest that uses the POST method
(one that has its method property set to URLRequestMethod.POST) as
using the GET method.
window:String (default = null) — The browser window or HTML frame in
which to display the document indicated by the request parameter. You
can enter the name of a specific window or use one of the following
values:
"_self" specifies the current frame in the current window.
"_blank" specifies a new window.
"_parent" specifies the parent of the current frame.
"_top" specifies the top-level frame in the current window.
urlRequest():
Creates a URLRequest object. If System.useCodePage is true, the
request is encoded using the system code page, rather than Unicode. If
System.useCodePage is false, the request is encoded using Unicode,
rather than the system code page.
Parameters
url:String (default = null) — The URL to be requested. You
can set the URL later by using the url property.

Related

How to notify the HTML container that the SWF has finished, using swfobject

I am embedding a flash object (swf file) into an HTML page. The object is written in as3 and built using Flash Builder. Its purpose is to show some animation, then finish.
It is really important to me to be able to notify the container that the animation has finished, but I can't find anything that works. I am using swfobject version 2.2.
Tried both on Chrome 40 and IE 11.
HTML (sample):
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript">
function flashFinished() {alert('finished!');}
</script>
<script type="text/javascript">
var flashVars = {}
var flashParams = {allowscriptaccess : 'sameDomain'}
var flashAttributes = {id : 'myflash', name : 'myflash'}
swfobject.embedSWF('myflash.swf', 'flashObject', '960', '720', '9.0.0', 'swf/expressInstall.swf',
flashVars, flashParams, flashAttributes);
</script>
</head>
<body>
<div id="flashObject">
<p>To view this page please make sure that an updated version of Adobe Flash Player is installed.</p>
</div>
</body>
AS3 (sample):
package
{
public class myflash extends Sprite
{
public function myflash()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
startPlay();
}
private function startPlay() : void {
// do whatever, then make sure function finishPlay is called in the end
}
private function finishPlay(event:TimerEvent) : void {
if (ExternalInterface.available)
ExternalInterface.call('flashFinished');
}
}
}
My "flashFinished" function gets never called. Can anyone suggest what am I doing wrong? Thanks!
To avoid that Flash player blocks your local swf to access to an external URL (internet, ...) or to communicate with javascript or some other actions that fire usually a security sandbox violation error, you have to add it (the swf) to the list of trusted locations like this :
For Flash Player PPAPI (like Opera and Chrome) :
Right click on your swf opened in the browser, then Global Settings... :
Which will open this page.
Then click on the Global Security Settings panel link at the right side, which will give you this page :
Then, as it's mentioned in the image, click on Edit locations... combo box, and Add location, which will give you this box :
You have just to type your swf location, or it's parent directory, or simply the whole partition like what I did in the image. Try to avoid "Browse ..." buttons, sometimes it doesn't work (at least for me). Confirm and close the page and refresh that of your swf.
For Flash Player ActiveX (like IE) and NPAPI (like Firefox) :
Right click on your swf opened in the browser, then Global Settings..., you can also go to your system control panel and open Flash Player :
Then go to Advanced tab and click Trusted Location Settings... button :
Then you have to add the swf location using Add.. button > Add File... or Add folder... button > select your file/dir or partition and press OK, Confirm and close all dialogs.
Then you have just to refresh your page.
In case the job of flash code is done and you don't need it anymore, just terminate the javascript in as3:
var exitStr:String = "javascript:terminate()";
navigateToURL(new URLRequest(exitStr),"_self");
And then add a onUnload function in HTML which will be called at that point:
onUnload="flashFinished();"
note: I used this code with swfobject v1.4 not sure about v2.2
It was actually a matter of security, due to the local environment, as suggested by #akmozo. I went to the global security settings of Flash Player:
http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html
and added the root folder of the tree contaning all HTML pages / SWF objects to the allowed locations. So now it also works locally.

how to make swf player with flex builder?

I make Sampal.swf with adobe flash. It has some external links to load some swf files into this main Sampal.swf. Now I want to run this main swf with flex builder application. I used mx:SWFLoader to that. This is code I had given...
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:ns1="*"
applicationComplete="init()" name="Content" showStatusBar="false">
<mx:Script>
<![CDATA[
private function init():void
{
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
}
]]>
</mx:Script>
<mx:SWFLoader x="6" width="770" height="336" source="E:\Office\Sampal.swf"/>
</mx:WindowedApplication>
When I run the application Main swf work properly. But that external links not works. If I click that kind of link, It gives this Error message.
Error #2044: Unhandled ioError:. text=Error #2035: URL Not Found. URL: file:///Flash/IRI02-I-07-I.swf
Please give me some solution...
According to the documentation:
The value of the source property represents a relative or absolute URL;
a ByteArray representing a SWF, GIF, JPEG, or PNG;
an object that implements IFlexDisplayObject;
a class whose type implements IFlexDisplayObject;
or a String that represents a class.
It appears that you have specified a disk path. Change this to a URL, or use another method to put the data in a format that SWFLoader can use.

Flash compiled with Flex SDK very big file size

I had a simple flash video player I was compiling using Adobe Flash Builder , but now I am compiling it using Flex SDK 4.6 . Flash filesize was 20KB when I was compiling with FB . Now it's 280KB . I know that it adds some swc files to swf build , I have disabled debug etc instructions provided here http://livedocs.adobe.com/flex/3/html/help.html?content=performance_06.html . Is it possible to somehow convert fla components without using mxml ?
Here is my mxml code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application backgroundColor="#000000" xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" minWidth="320" minHeight="240" creationComplete="initApp()">
<fx:Script>
public function initApp():void{
var p = new video_player(uic);
}
</fx:Script>
<mx:UIComponent id="uic" />
</mx:Application>
video_player.as
....Import statements
public class video_player{
private var uic:UIComponent
var fullScreen:Image;
var rtmpApplication:String;
var streamName:String;
public function video_player(_uic:UIComponent) {
uic=_uic;
if (FlexGlobals.topLevelApplication.parameters.hasOwnProperty("applicationName")) {
rtmpApplication=FlexGlobals.topLevelApplication.parameters.applicationName;
}
if (FlexGlobals.topLevelApplication.parameters.hasOwnProperty("streamName")) {
streamName=FlexGlobals.topLevelApplication.parameters.streamName;
}
vPlayer=new Video(playerwidth,playerheight);
uic.addChild(vPlayer);
init();
}
public function init(){
//add fullscreen image in flash top right , and event handler
//Code to connect to live application and play video using NetConnection and NetStream
}
}
Is there any way around this?
Also I have added option -static-link-runtime-shared-libraries=true so it wont download anything runtime . Without that flash size is 49KB
By setting the above option, you have told the compiler to include all of the Flex framework classes (that are used by your application) in the application SWF. So your SWF grows from 49KB to 280KB.
This is the "RSL" thing (runtime shared library) that #Reboog711 and I were talking about. If you use the Flex RSL's, then all of that Flex framework code is not included in your application SWF. The Flex framework RSL's are signed by Adobe and can be cached by the Flash Player. So using them is always preferable. (Note: I'm assuming this all still works with Apache Flex)
Finally, I wish to reiterate that in Flash Builder there are two basic kind of projects you can create: Flex project, Actionscript project. I'm ignoring the mobile options, but the same applies to them:
An Actionscript project will, in general, result in a smaller SWF because you are not relying on any of the Flex framework classes. It sounds like you could make your video player app even smaller (closer to the 20KB size you originally had) if you were to create an Actionscript project.

Handle ExternalInterface Call, comming from local swf file, in Adobe Air 3.4 Actionscript 3 application

So We got a playlist with various swf files, some old as2 animations, some newer.
We download them to a local folder, and can play them fullscreen. all with one AIR (actionscript) application. Now we know that in the newer files there are ExternalInterface.Call(some arguments) calls. And we need to handle them in the hosting AIR application. So far we have a class inherrited from MovieClip, with the following constructor:
public function FlashClip()
{
ExternalInterface.addCallback("FlashPlayerControl1FlashCall",FlashPlayerControl1FlashCall);
}
when we run the application whe got the following error:
Error: Error #2067: The ExternalInterface is not available in this container. ExternalInterface requires Internet Explorer ActiveX, Firefox, Mozilla 1.7.5 and greater, or other browsers that support NPRuntime.
at Error$/throwError()
at flash.external::ExternalInterface$/addCallback()
at Video::FlashClip()[C:\Users\Daan\Adobe Flash Builder 4.6\TINS-v2-1\TINSV2\src\Video\FlashClip.as:12]
at Video::FlashPlayer/BestandOpend()[C:\Users\Daan\Adobe Flash Builder 4.6\TINS-v2-1\TINSV2\src\Video\FlashPlayer.as:43]
On the following line:(FlashPlayer.as:43)
var clip:FlashClip = new FlashClip();
So, My question is this. Is what we are trying to do even possible. Or do we need tot embed a javascript container in the actionscript AIR application? Or does anyone know how we are going to get this to work?? Note: We cannot alter the existing swf files. we dont even have the original .fla's
The documentation says what you are trying to do is not possible:
In Adobe AIR, the ExternalInterface class can be used to communicate
between JavaScript in an HTML page loaded in the HTMLLoader control
and ActionScript in SWF content embedded in that HTML page.
For ExternalInterface to work, it needs to communicate w/a Javascript "layer" that the browsers provide. You won't get this functionality in AIR, unless you load an HTML page that has your SWF content embedded in it.
I've linked to the docs for HTMLLoader which would allow you to do this.
[Edit]
Appending a simple AIR app (note it's Flex 3.6, sorry that's what my client uses) that loads a web page, in case it helps.
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
width="800" height="600"
creationComplete="onCreationComplete()">
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
private function onCreationComplete():void
{
var loader:HTMLLoader = new HTMLLoader();
var request:URLRequest = new URLRequest("http://www.adobe.com");
loader.width = 800;
loader.height = 600;
loader.load(request);
var uic:UIComponent = new UIComponent();
uic.addChild(loader);
addChild(uic);
}
]]>
</mx:Script>
</mx:WindowedApplication>

Change Webbrowser background color in WPF

I have webbrowser control in my xaml code and i want to change it's document's background color.
<WebBrowser Source="http://google.com" x:Name="IE" Navigated="IE_Navigated" />
private void IE_Navigated(object sender, NavigationEventArgs e)
{
HtmlDocument document = (HtmlDocument)IE.Document;
var color = System.Drawing.Color.Black;
document.BackColor = color;
}
it's not working;
The reason why it doesn't work is because you have a mix of WPF WebBrowser and WinForms WebBrowser and they are not compatible.
Your XAML is creating a WPF WebBrowser, but in the Navigated event, you are casting IE.Document as HtmlDocument, which is the type for the WinForms WebBrowser. Consequently that cast will fail.
Even if you change it to work, there is a further problem in that the Navigated event is fired once downloading has started, not after it has finished (as documented on MSDN). The WPF WebBrowser does not have a DocumentCompleted event like the WinForms WebBrowser does.
If you want this functionality in a WPF application, a simple approach is to use the WinForms WebBrowser instead of the WPF version. This is done by hosting it in a WindowsFormsHost as shown below:
<wfi:WindowsFormsHost Name="host" />
You have to include a reference to System.Windows.Forms (which you probably already have) and WindowsFormsIntegration, and then define the namespace as:
xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
And in the code-behind:
webBrowser = new System.Windows.Forms.WebBrowser();
host.Child = webBrowser;
Then to navigate:
webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
webBrowser.Navigate("http://google.com");
Then to set the background to black, you would do so on the body, like this:
void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlDocument document = (HtmlDocument)webBrowser.Document;
document.Body.Style = "background-color:black";
}
I have tested this and it works.