how to make swf player with flex builder? - actionscript-3

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.

Related

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.

Display HTML page in browser window upon clicking a button

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.

Embed images from swf file in flex

How to create vector images swf file in flash, and how can i use the swf file to get images in flex.
Could you please some one help me on this.
Thanks in Advance.
If I understand you correctly, you have a swf file created in Flash CS6 (or similar) that you wish to use in a flex project. Is this correct?
If it is, then you would use swfloader to load your swf file in a flex app.
example:
<fx:Script>
<![CDATA[
import mx.managers.CursorManager;
[Bindable]
public var loadModHome:String = "assets/flashFiles/home_trusted.swf";
protected function analyticsBtn_clickHandler(event:MouseEvent):void
{
loadModHome="assets/flashFiles/home_trusted.swf";
}
protected function integratedBtn_clickHandler(event:MouseEvent):void
{
loadModHome="assets/flashFiles/home_integrated.swf";
}
]]>
</fx:Script>
Then in your component/app/module etc place the swfloader tag and fill it in as needed. Here I have bound the source to a variable called "loadModHome" this makes the swfloader dynamic in that I can assign a new value to my variable and have it unload and load different swf files. I do this by using the click event of two buttons, this allows me to toggle the swf files on the fly
<mx:LinkButton id="analyticsBtn" label="Trusted Analytics" textDecoration="underline"
color="blue" click="analyticsBtn_clickHandler(event)"/>
<mx:LinkButton id="integratedBtn" label="Integrated Billing" textDecoration="underline"
color="blue" click="integratedBtn_clickHandler(event)"/>
<s:SWFLoader id="homeMainSL" x="127" y="10" width="600" height="800"
source="{loadModHome}" click="homeMainSL_clickHandler(event)"
useHandCursor="true" buttonMode="true"/>
To see a working example check out http://www.myfirerules.net. The site is a work in progress. The home page has a s:SWFLoader tag to load the Flash created swf files, the other pages use a s:ModuleLoader tag instead to load swf files created by flex.
Hope this helps
Jim

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>

instantiating a Flex app from within AS3/OpenLaszlo

I have one OpenLaszlo/AS3 App (olapp.lzx) and one Flex App (flexapp.swc).
I want to include flexapp.swc in olapp.lzx as follows:
olapp.lzx (AS3):
===============
...
var flexapp:Sprite = new FlexApp();
flexapp.doSomething();
...
The flexapp.swc is compiled from this mxml:
flexapp.mxml:
============
<?xml version="1.0"?>
<!-- intro/FlexApp.mxml -->
<mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<mx:ComboBox>
<mx:dataProvider>
<s:ArrayList>
<fx:String>AK</fx:String>
<fx:String>AL</fx:String>
<!-- Add all other states. -->
</s:ArrayList>
</mx:dataProvider>
</mx:ComboBox>
</mx:Application>
When I compile flexapp.mxml to swf, it runs nicely, but instantiation from AS3
fails (TypeError: Error #2007). I researched that mxml->as3 integration is not the usual way to go, but for this particular case I need to. I have to admit that I'm not yet too familiar with Flex, only OpenLaszlo. What should be changed in flexapp.mxml? Thanks!
OpenLaszlo does not officially support importing a Flash SWF application into it. The only exception are movies encoded to the SWF format.
(If your application is in Flash 9 (SWF9) or greater then the SWF movies need to be encoded in AVM2 format, for Flash 8 or lower, the AVM1 codec).
If you attempt to load a SWF that is anything other than a simple SWF movie into an OpenLaszlo <view> then the result will be unpredicatble.