I've imported an FXG from illustrator from Adobe illustrator into flash builder 4.5 and have managed to get it on the stage, the problem I'm facing is accessing the children of the FXG.
Basic FXG that won't work:
<?xml version="1.0" encoding="utf-8" ?>
<Graphic xmlns="http://ns.adobe.com/fxg/2008" xmlns:ATE="http://ns.adobe.com/ate/2009" xmlns:ai="http://ns.adobe.com/ai/2009" xmlns:d="http://ns.adobe.com/fxg/2008/dt" xmlns:flm="http://ns.adobe.com/flame/2008">
<Group id="subChild">
<Group id="subSubChild" />
</Group>
</Graphic>
I then try to access these children like so:
var fooObj:MyFxgObj = new MyFxgObj();
fooObj.getChildByName("subChild");
Which promptly greets me with a null error. I've searched google for the past 2 hours or so but to no avail, so any help would be appreciated.
Since you said my comment was your solution, here it is as a formal answer:
I didn't think accessing the children of an FXG graphic was possible. I think FXG assets exist at a different level than ActionScript objects or native flash objects. I view an FXG file as a single asset; kind of like a JPG or PNG or embedded SWF.
If you need to access the children, using MXML graphics is the approach you should consider.
Accessing FXG children is possible and explained in the Adobe doc Using FXG.
Related
I have one AS3 application which was developed entirely in AS3 without using single line of code in MXML. Of late I am realizing that MXML has some rich controls which are not provided in open source Apache Flex SDK. One library which is of most interest to me in mx.controls, it includes Label, DataGrid etc.
Now, I want to extend my AS3 application to call mxml compiled into swf file. I tried to import mx.controls inside my AS3 programs but it does not sense that. Please tell me if I am doing anything wrong. If I am able to import mx.controls inside as3 class it would save me a lot of time. Can I do this?
Alternatively, I am trying to write a few applications in mxml and then call (.swf) in AS3. Is it possible?
I tried Googling but all examples are pointing to using ActionScript inside MXML with [CDATA[]]. But I want the inverse. Calling MXML from ActionScript.
Please explain me at nuts and bolts level as I am struggling with this a lot.
thanks in advace
You can't do that because Flex, that uses MXML, is framework built on top of the Actionscript. But you can do reverse. In Flex MXML you can use Actioscript code, and you can also use Flash components like Sprite, MovieClip... by using UIComponent or SpriteVisualElement as their parent container.
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.
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.
The code at the bottom of this post nests an AS2 "player" inside a Flex app (AS3). Look at the part that says "[AS2 player swf]". That AS2 player swf has almost no code - just one function that loads an asset from a remote server. Very simple:
this.onLoad = function(){
content.loadMovie("http://URL_TO_REMOTE_SWF");
};
And it has no other assets. Just one MovieClip - "content".
So we've got a Flex app that loads an AS2 swf that loads a remote swf. No dice. Remote swf doesn't load and display. No errors reported.
Important: The AS2 app on its own works. If I go navigate to it in my file system and double click, remote swf does indeed load and display. So I've established that the unwrapped AS2 swf player works and does indeed load remote swf's. Something about nesting that player inside the Flex app creates a problem. Are you not allowed to do this - 3 levels of swf nesting (child - parent - grandparent)?
UPDATE: Target remote swf's load and display fine directly in Flex as well (skipping AS2 swf). So problem doesn't appear to be with AVM1/AVM2 discrepancy between target content and Flex app. Could be AVM1/AVM2 problem with how the Flex app displays the AS2 swf but only when it contains content.loadMovie("http://URL_TO_REMOTE_SWF"). Loads and displays without that line.
UPDATE: This is a Flex packaged IOS application and thus is subject to ActionScript restrictions for dynamically loaded code. But it doesn't work in a regular Flex (non packaged IOS) app either which is not subject to these limitations. THE FOLLOWING CODE SHOULD WORK AS FAR AS I CAN TELL IN A REGULAR FLEX BROWSER BASED APPLICATION.
<?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"
xmlns:mx="library://ns.adobe.com/flex/mx"
initialize="init()">
<fx:Script>
<![CDATA[
import mx.core.UIComponent;
private var request:URLRequest = new URLRequest("[AS2 player swf]");
private var loader:Loader = new Loader();
private var myComponent:UIComponent = new UIComponent;
private function init():void{
myComponent.percentHeight = 100;
myComponent.percentWidth = 100;
loader.load(request);
myComponent.addChild(loader);
player.addElement(myComponent);
}
]]>
</fx:Script>
<s:Group id="player"
height="100%" width="100%"/>
</s:Application>
Since all Sprites and MovieClips are both display objects and display object containers, you could theoretically keep nesting them forever. There are physical restraints, of course, but I see no reason why there should be a limit other than memory and processing power (at some point, refreshing the screen will become sluggish, and eventually painful to wait for).
I've searched the web to see if I could find any information about a built-in limit enforced by the AVM, any documents or error codes that would suggest there is one, but I couldn't find anything at all. Of course, that doesn't mean there isn't - it just means the limit hasn't been reached by many people yet ;)
So if anyone else knows more...
EDIT
Since the information about your loaded MovieClip is new, here's my update: AVM1 (AS1 & 2) SWFs don't always execute in the same way when loaded into an AVM2 (AS3) movie. This has nothing to do with the number of nested display objects. I originally thought this was because the _lockroot property was removed in AS3, but I've searched a bit and found out it is assumed true by default, and should therefore not be a problem.
There may be many things about your scenario that are different from when the file runs on its own, and I would start by looking at these:
Do you use relative path names to load other data into the AS2 swf?
Do you get any error messages (particularly, security sandbox violation errors)?
Does your AS2 SWF rely on external variables to be set (FlashVars)
Does your AS2 SWF need ExternalInterface access?
FINAL EDIT
Since this new info has just come up:
There is absolutely no way to execute dynamically loaded AVM byte code on an iPad at runtime, for the same reason that there is no Java VM and no Flash Player for iOS: Apple does not allow the execution of dynamically loaded byte code at all. Period.
Hence, you can load and play SWF animations, but not ActionScript. It will simply be ignored. Also, neither of the apps that you did run is in fact AVM byte code - they are compiled into LLVM byte code instead.
You will have to find a way to check for the end of the animation that does not involve stop() commands. Perhaps this can be done by checking frame numbers from your AS3 container?
To answer you question directly, yes, you can load AS2 swfs that way. And you code looks correct to me.
I suspect it is loading the AS2 swf fine, but that the AS2 swf is not initializing correctly for some reason. Perhaps it is a video player that has no visible assets besides the loaded video. AS2 tends to fail without throwing errors, which makes it hard to debug. I would suggest publishing an AS2 swf with some graphics in it but with no code that could fail. No code at all. Maybe just a timeline animation of a moving circle or something, then load that. In that way you can eliminate your Flex code as the source of the problem.
If it turns out that your test movie works, then you will need to determine what resource the loaded swf is expecting that it is not receiving.
I am trying to learn flex4 from adobe document and I am very confused while using three namespaces.. there is no way i can keep track of when to use what often ending up using fx inside mx or s or similarly making some stupid goofed up combinations of {fx,mx,s}.
Adobe document is huge and i am looking for some good starting point for learning flex .
Your question is quite large; however, some basic explanation about the 3 namespaces you've cited:
<fx> tags are typically programmatic functionality and not visual display objects. You'd use it for declaring a script block in a MXML document or defining variables in a declarative way.
<fx:Script>
<![CDATA[
[Bindable]
public var myVariable:String = "Hello, World!";
]]>
</fx:Script>
<fx:Declarations>
<fx:Object id="variableName"
property1="myCustomProperty"
property2="anotherCustomProperty" />
</fx:Declarations>
When declaring visual elements and UIComponents on the display list, you'll typically want Spark architecture; therefore, you'd use the Spark namespace.
<s:Group />
MX architecture is important, but is generally deprecated by Spark. If a component is available as Spark, you should use that implementation.
<mx:Box />
All are just packages of the framework, and really no difference than importing packages in ActionScript. Your custom components will use their package name as a namespace, or you declare a namespace for your Flex MXML library.
If you're using an IDE like Flash Builder, you usually don't have to worry about the namespaces.
In an MXML file, enter the start tag (ie: <), skip the namespace and start typing the class you're after. In the above examples, I'd hit <s for "script" and the intellisense will show you completion options that will insert the namespace for you.
If the auto completion options do not appear, hit [ctrl]+[space-bar].
Let Flash Builder help with namespaces by completing them for you.
Probably doesn't go far to helping you out, but hopefully this helps a little.
Have you tried http://www.adobe.com/devnet/flex.html especially Getting Started part?