instantiating a Flex app from within AS3/OpenLaszlo - actionscript-3

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.

Related

How to use an MXML component in my as3 code?

I have made a lot of research on this topic but I could not find any helping answer to my issue. I currently have a 100% as3 application. I would like to add a spark component to my stage eg a datagrid (because it is way more simple and clean to create it with mxml).
FileName : MXMLPractice.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:DataGrid x="0" y="0" width="50" height="50"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="dataField1" headerText="ColumnName1"></s:GridColumn>
<s:GridColumn dataField="dataField2" headerText="ColumnName2"></s:GridColumn>
<s:GridColumn dataField="dataField3" headerText="ColumnName3"></s:GridColumn>
</s:ArrayList>
</s:columns>
</s:DataGrid>
How can I add this component to the stage in my as3 code?
Given my difficulties to find a matching answer, I guess I might be trying to do something not recommended. If that is the case, could you please advise me what to do instead?
My tests so far (compiling but not displaying anything) :
package
{
import flash.display.Sprite;
import mx.events.FlexEvent;
public class Main extends Sprite
{
private var practice:MXMLPractice;
public function Main()
{
practice = new MXMLPractice();
stage.addChild(practice);
}
}
}
In pure AS3 project, you should use AS3 components, that also extend UIComponent as flex components, but designed for pure as3 project. For this task, you will need fl.controls package. You can copy/past ui classes from the installation directory of Flash Professional:
c:\Program Files\Adobe\Adobe Flash CC\Common\Configuration\Component Source\ActionScript 3.0\User Interface\
Next step will be export view representation of ui components to the library in Flash IDE from components window CTRL+F7
It's really hard task.
If you want to use some simple class from Flex SDK like ObjectUtil just copy it to your classes. It will work fine because doesn't have imports.
But visual components are linked with many other classes. For components like grid you have to copy dozens of classes. Each of them also have dependencies and so on.
Probably it's better to modify Flash component or find open source solution.

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.

Action script mobile project. how to add datespinner

How should I add dateSpinner component to action script mobile project?
As a Flex component, DateSpinner is only available from the spark.components package; therefore, not included in pure ActionScript projects.
Implemented within the Flex framework, the spinner is rendered from Flash for ubiquitous delivery across multiple platforms.
Although there may be native extensions, AIR does not expose native controls such as UIDatePicker.
If you're using Adobe Flash Builder, instead of an ActionScript Mobile Project, you could create a Flex based application:
An example MXML implementation:
<?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"
applicationDPI="160">
<s:DateSpinner id="dateSpinner"
displayMode="dateAndTime"
selectedDate="{new Date(2013, 3, 12)}"
minDate="{new Date(2013, 0, 1)}"
maxDate="{new Date(2013, 11, 31)}"
minuteStepSize="5" />
</s:Application>
Would then produce the following:

Flash Builder (Flex) Air Project mx.* libraries swc Class mx.logging.targets::LineFormattedTarget could not be found

A teammate on my project added a swc that had some mx logging classes in it, and now my project won't compile. Error:
Class mx.logging.targets::LineFormattedTarget could not be found.
I'm on the latest Flash Builder 4.6, fresh install. I notice when I go to project > properties > Actionscript Compiler then select Libraries, there is no options to select MX like there was before. Anybody know how to solve this problem. I thought the idea behind swc's is that they are self-contained and wouldn't need to me add extra imports. Thanks.
Yah very strange... so after discussing above a bit I threw together a sample project and this compiles fine against the 4.6.0 SDK I'm using, I can see the LineFormattedTarget class within my framework.swc when I expand it in the libraries in the navigator on the left:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="windowedapplication1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.core.mx_internal;
import mx.events.FlexEvent;
import mx.logging.targets.LineFormattedTarget;
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
var test:LineFormattedTarget = new LineFormattedTarget();
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:WindowedApplication>
I would check to make sure it shows the framework.swc inside of the 4.6 referenced library, if the swc isn't there try removing and re-adding the framework to the library path, if that fails with the same result I would look at pulling down the SDK fresh.