How to create an AIR application in Flash Builder 4 without mxml - actionscript-3

I am an actionscript developer and I know nothing when it comes to mxml. recently switched to using flash builder and I really like it but I want to create an AIR application in flash builder but I don't want to use mxml since I don't need any of the built in framework to accomplish my goal.
Is that possible?
If I have to use mxml to start the application how do I use .as files with .mxml files?
So far I have been able to import a .as file, but I can't use addChild(). If I can get some help on how to do that I would be so grateful I have spent hours on end failing at this. Thanks

create a class (in .as file) extending UIComponent and use it as a root display object, add a creationComplete listener in the constructor and use it as an entry point. and so the only mxml code you need is:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/halo"
xmlns:loc="*"
xmlns:s="library://ns.adobe.com/flex/spark>
<loc:YourRootClass/>
</s:Application>

Recent versions of FlashBuilder allow for creation actionscript AIR project directly. If this isn't your case, just create new AIR MXML application, add new actionscript class and set it as default application. Then you can remove MXML. Also see this for details.

Related

How to instantiate a mx comobox in a pure actionscript project on flash builder

I am trying to use the following code in a pure actionscript project ( no mxml ) on flash builder :
import mx.controls.ComboBox;
...
...
var cmb:ComboBox
....
addChild(cmb)
....
But when compiling, the combobox does not appear. I can see it in the mxml version though.
I don't think, mx and spark can be used unless it's mxml project. But anyways i solved, by using the combobox in flash ide, and creating a swc file. And then using fl.controls.ComboBox in the flash builder.

how to share a component in as3

I have a custom component(eg. MyButton) used in several swfs. I'd like to share the component in runtime, thus once our designer change the button's visual effect, we need not publish all flas that uses this button.
In as2, I can put this button in an asset fla(eg. lib.swf) and check the "export for runtime share" in symbol property. Then copy the button to a fla(eg. main.swf) and check the "import for runtime share", this works fine. However in as3, after doing above, if I put a button instance on stage and modify its inspectable property, i'll get a compile error "1046:Type was not found or was not a compile-time constant".
I searched the web and found this http://www.kirupa.com/forum/showthread.php?317257-Runtime-Shared-Library-woes. Then I tried the swc approach, but it seems swc will be compiled into swf, it doesn't share at all.
the shared component must be put on the stage, because all fla will be modified by our designer while he knows nothing about programing.
we can not use flex, all operation must be done in Flash CS5.
1: Placed on Library all of your components to .fla as follows: my fla names BrushClip.fla the components wrapped a MovieClip. and be ActionScript Linking export to ActionScript Class.
2: File - Publish Settings check SWC format and publish as follows:
3: check, created swc file in your project. now you can using a swc other project you must linking to SWC library in File-ActionScript Settings-Library Path. and later if you change a components design, re-publish. and copy and paste swc file. automatically will change restart swf file. BrushClip.swc has a all components.
you can access as follows:
var brushClip0:MovieClip = new BrushClip0();
addChild(brushClip0);
var brushClip10:MovieClip = new BrushClip10();
addChild(brushClip10);
I've found the solution.
Give the Sprite that holds the imported components a binding class
Edit the class file, declare the components yourself regardless of whether checked the "auto declare instance on stage"

Can I make a FlexMobile project pure as3?

I've got an as3-robotlegs (signals) app that I want to run as a mobile project. I've discovered I can't have a pure as3 entry class ie.
this works fine for a Flash professional or pure as3 project
public class TestX extends Sprite
{
protected var context:ApplicationContext;
use namespace mx_internal;
public function TestX()
{
LoaderConfig.mx_internal::_url = loaderInfo.url;
LoaderConfig.mx_internal::_parameters = loaderInfo.parameters;
context = new ApplicationContext(this); <---
this.stage.nativeWindow.visible = true;
}
}
now for FlexMobile I need to do something like this in index.mxml
<fx:Declarations>
<context:SignalCafeContext contextView="{this}"/> <----
</fx:Declarations>
But do I really need to convert all my flash components to Flex UIComponent or is there a way I can use pure as3 (no mxml) in a FlexMobile project?
Thanks
Edit:
Took me a few days to churn through these great answers... all of them correct as I far as I can tell, I found amy's publishing arbitrary swfs works great, i found it easier to go with a pure actionscript mobile project
Command-line Adobe AIR Developer Tool (ADT) can package a SWF for mobile.
This way, any monolithic SWF created from various toolchains may be packaged for mobile.
Download AIR 3.5 SDK.
Assure JRE, or use the one from Flash Builder.
Execute adt to package your SWF to an IPA:
adt -package -target [ipa-test | ipa-debug | ipa-app-store | ipa-ad-hoc]
-keystore iosPrivateKey.p12 -storetype pkcs12 -storepass qwerty12
-provisioning-profile ios.mobileprovision
HelloWorld.ipa
HelloWorld-app.xml
HelloWorld.swf icons Default.png
Otherwise, Flash Builder 4.6 has pure ActionScript mobile projects:
Select File » New ActionScript Mobile Project
Although a Flex SDK is referenced for AIR, the project will be pure ActionScript.
Choose mobile settings.
Assure all references are merged in to code.
Which will stub your project as:
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
public class X extends Sprite
{
public function X()
{
super();
// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
}
}
}
But do I really need to convert all my flash components to Flex
UIComponent or is there a way I can use pure as3 (no mxml) in a
FlexMobile project?
In Flash Builder 4.6 you can create an ActionScript Mobile project; which should do what you want. Creating a Flex Mobile project, assumes you will have dependencies on the Flex Framework and imposes some specific patterns on you, such as having your main application file be an MXML file that extends Application.
You can just take your swf and publish it for mobile, using these steps.
Create a new ActionScript Mobile Project and give it a name.
Go to Project -> Properties -> Builders.
Uncheck the “Flex” builder (but leave the “AIR application.xml Builder”)
Now copy your arbitrary swf (ie: myapp.swf) into the bin-debug folder.
Create an ActionScript class with the same name as the swf, (ie: myapp.as) in the default package space.
Right click on the myapp.as file and click on “Set as Default Application”
Now it will generate a myapp-app.xml, go and open and edit as you like.
Click on run configuration and package your app for you the platform you want.
Repeat steps to add more SWFs to package.
You can also find steps to go back and forth between Flash Pro and Flash Builder here.

Flashbuilder: ActionScript only Project, compiler metadata

If one creates an ActionScript only project in Flash builder, one can set things like stage size and framerate as metadata like this
[SWF(width='400', height='300', backgroundColor='#ffffff', frameRate='30')]
as described here: http://www.adrianparr.com/?p=36
I wanted to ask what other settings i can set using such metadata? is there somewhere a complete list?
See Adobe's documentation:
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf680e1-7ffe.html

automation errors in Flex Builder 3 when importing a swc from Flash CS 5

I am facing a really weird issue while trying to use an "swc" file imported from Flash CS5, that I am trying to use in Flex Builder 3 (by converting symbol to "Flex Component"). The errors are coming in files which are not even remotely related to the "swc" file that i am importing.
Now, I know that the automation stuff has come as a part of FB4, but I don't really have an option to migrate to FB4.
I have tried to change the flex sdk settings in Flash CS5 (steps given below), but that has not helped.
Edit-->Preferences-->Actionscript-->"Actionscript 3.0 Settings"-->"Flex SDK Path" (pointing this to flex3.5 sdk instead of Flex4.0 sdk)
I feel that the issue is most probably a compatibility issue b/w Flex 3 and Flex 4, but have not been able to find a workaround for the same. Any help is greatly appreciated.
Thanks,
Kapil
Here is the trace:
Severity and Description Path Resource Location Creation Time Id
1044: Interface method createAutomationIDPartWithRequiredProperties in namespace mx.automation:IAutomationObject not implemented by class com.sparsha.view.ui:SchematicWindow.
1044: Interface method createAutomationIDPartWithRequiredProperties in namespace mx.automation:IAutomationObject not implemented by class
1044: Interface method get automationEnabled in namespace mx.automation:IAutomationObject not implemented by class com.sparsha.lib.controls:CloseableTabBar.
1044: Interface method get automationEnabled in namespace mx.automation:IAutomationObject not implemented by class
1044: Interface method get automationEnabled in namespace mx.automation:IAutomationObject not implemented by class com.sparsha.lib.layouts:DockedAppLayout.
OK, first, the error: this means that Flash probably generated a class for the symbol you are importing using a certain template, where the template doesn't fit the SDK you are using to compile the project. Specifically, the generated class did not implement the methods listed in the error message. I.e. your framework.swc has a definition of mx.automation:IAutomationObject that has method createAutomationIDPartWithRequiredProperties() (nice name btw), but Flash generated code that reads as
package com.sparsha.view.ui {
import mx.automation:IAutomationObject;
public class SchematicWindow implements IAutomationObject { . . . } }
Since you cannot do anything about Flash not generating the method you need, your only way is to monkeypatch the SDK. I.e. copy the mx/automation/IAutomationObject.as from the SDK sources to the classpath of your project. Remove the conflicting method declaration (this may or may not result in other errors). If it results in further errors, repeat the same procedure for every class that "misbehaves"...
However, monkeypatching will mean that you are no longer able to use framework RSLs, as they will come with the original version. So, I would try to avoid the problem altogether and look for another way of exporting symbols from Flash IDE, for example, by not making them a Flex component. Or, if you really insist on them being a Flex component, then bootstrap the FlexSprite, for example, and assign your Flash symbols the bootstrapped class as the "parent class".
I was also having this problem recently. I would get the errors when I included the flash generated swc in my flex projects lib folder.
I was able to work around the issue by upgrading my flex to the flex 4.5.1.21328A SDK.
Additional Details about my project that might help others:
My swc was generated from Flash Professional CS5.5 and my Flex Project was being used in Flash Builder 4.5.
My swc was published to Flash Player 9 with ActionScript 3.0.
My flex project was using the 3.5.0.12683 SDK.