Package flash game to AIR mobile (IPA) - actionscript-3

I have a complicated game project using multiple libraries, swc, assets, etc. The output is a two swf files (shell with the menu and the game itself). Packing in IPA (iOS) does not work immediately because of a lot of problems and settings ANT. But build as swfs work fine.
Is it possible to create a separate mobile as3 project, which will load the first swf to full screen, which will load the second swf, and then build it? How best to do this? Or are there other options?

Try this:
Compile a copy of your main game swf as an swc.
In a copy of your menu swf, point it to the game swc and in the place you would normally go through the motions of loading the external game swf, just directly add a new instance of the root game class:
// Before:
var ldr:Loader = new Loader();
... other stuff, progress monitoring, etc. ...
var mcGame:MovieClip = ldr.content as MovieClip;
// After - one line:
import my.game.namespace;
var mcGame:GameClass = new GameClass();
Compile this updated menu project as a swc.
In your mobile app, add an instance of the root class of the menu stage:
// Constructor for root class of mobile app
public function AppRoot() {
this.addChild(new GameMenu());
}
Now everything is bundled in a single compiled project.

Related

MovieClip assets SWC from Flash inaccessible in Flash Builder using getDefinitionByName

I need to access MovieClips from an SWC created in Flash using getDefinitionByName() in Flash Builder. I know I have to add in the full package name whilst doing this, like so, with the package name being 'com.fusepump':
var className:String,
assetName:String,
obj:Class,
i:uint;
for (i = 0; i < Config.ASSETS.length; i ++)
{
className = String('com.fusepump.' + Config.ASSETS[i]);
assetName = String(Config.ASSETS[i]).charAt(0).toLowerCase() + String(Config.ASSETS[i]).substr(1, String(Config.ASSETS[i]).length);
obj = getDefinitionByName(className) as Class;
_assets[assetName] = new obj();
}
The problem is that I don't seem to have any control of the package name in the SWC exported from Flash. In the Referenced Libraries directory the MovieClips are under Assets.swc/default package/Asset_1.abc - If I were able to add it to a named package the problem would be solved.
I had such problems too. Try this solution Flash Builder - How to build or include an SWC you can build SWC in flashBuilder. The ones from flash ide are wierd to use in FlashBuilder.

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"

ApplicationDomain clarifiation needed

I need some clarification on this subject as I just ran into an issue with loading swfs into a reused loader object.
So lets say I have 3 SWFs.
Main.swf
childA.swf
childB.swf
Main.swf has a loader object in it that gets reused (myloader.load("childA.swf")) and childA or childB swf will be loaded via user interaction.
Both child swfs have a com package with a class in that package called config.
The config files are different files for both classes just named the same.
both child swf also dispatch an event that the Main listens for
Now the problem I had was if childA was loaded first then after childB was loaded it would still show as childA. Basically, whichever one got loaded into that loader first would be the winner.
This drove me nuts as nothing I did would cause the swf to unload. Not until I found the following code.
var appDomain:ApplicationDomain = new ApplicationDomain();
var context:LoaderContext = new LoaderContext(false, appDomain);
_contentPanel.load(new URLRequest(str), context);
I stumbled over this code on a post somewhere talking about how to truly unload a swf. Apparently, This also applies to how to truly load a swf.
As you can see a new appDomain is created and assigned to the context when loaded.
This works like a dream I can now load and unload all day long.
My confusion is the event that the child dispatches still works, when I don't think the Main swf should pick it up due to it not being in the same appDomain.
I mean shouldn't the event be blocked?
Unloading a SWF
The Loader class provides Loader.unload() (or after Flash Player vers. 10 - Loader.unloadAndStop())
Problem with the second loaded SWF being overridden by the first
Objects that are stored in ApplicationDomains are stored by their class-name and I wonder whether the class names of the loaded SWFs (or their children) are overriding. Even if that isn't the case; why not use a new instance of the Loader for each object being loaded?
How the Main SWF can pick up both children from another application domain
The Main SWF will be able to work with the new (loaded) application domains because they are child-domains of the Main SWF's (See ApplicationDomain.parentDomain). The Main SWF's domain will be the 'system domain' and the new instances will be loaded below it.
Splitting the loaded SWFs from the Loader
Ideally you want to have access to the SWF data irrelevant of the state of the Loader. You can do this by accessing the root movieClip of the SWF once loaded and create a new instance with
var rootClipClass:Class = ApplicationDomain.getDefinition("[InsertYourRootClipName]") as Class;
var rootClip:MovieClip = new rootClipClass();
At that point you can unload the loader and work with your fresh instance cleanly.
Further reading
Difference between Loader.unload() and Loader.unloadAndStop()
Working with Application Domains - Adobe Docs
Loader class reference
ApplicationDomain class reference

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.

flash cs5: compiling fla with huge internal library takes YEARS !

by using flash cs5 with a huge internal image library (over 300+ small png-files) i need more than 90seconds for each compiling action! the as code is pretty well, also my computer (quad core, 4gigs of ram). i've found out, that by exporting the files to "stage 1" (bild 1 in my screenshot) flash starts to hang around, but i don't know why...
.
how to speed this process up ?
__________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________
my solution did not work:
so i've played around and ended up creating *.as-files for each single bitmap, but the speed-result is the same (maybe 10% - 15% faster than before)...
package
{
import flash.display.*;
dynamic public class MY_BITMAP_NAME extends BitmapData
{
public function MY_BITMAP_NAME(width:int = 500, height:int = 135)
{
super(width, height);
return;
}
}
}
i can not work fast enough to debug my project files :-(
The solution would be to move your assets inside a precompiled SWC library that you will only recompile when they change.
Building the library:
create a new FLA and move in your Bitmaps,
each image needs to have a linkage class name and be exported in first frame; you don't have to create an AS class, Flash will generate them,
in the publish settings, "Flash" tab, check "Export SWC",
this SWC library will be published in the same location as the SWF; in CS4-5 you can't prevent the SWF creation.
Using the library
in your main FLA publish settings, "Flash" tab, open the Advanced Actionscript 3 settings dialog,
in the "Library path" tab you can add the assets library SWC; make sure the "Link Type" is "Merged into code",
SWC content will be available in your main FLA as if they were in the library.
It is worth noting that:
you must instantiate these assets by code (ie. new AssetName): they will not appear in your main FLA's Library panel and you can not drop them on the timeline,
only assets you explicitly reference in your code will be available at run time; if you are using getDefinitionByName() you must still import the assets somewhere in your code. For instance you can declare an Array containing all your assets classes (ex: var assets:Array = [AssetClass1, AssetClass2,...]).
if these 300+ images don't change too often, you could create a second .fla, where you only put the images in the library. Then you publish that .fla as a swc file (You can set this in the publish settings).
And you use that swc in your original .fla (that now has no images anymore), where you have your code (using the swc means, in the publish settings -> actionscript settings, you set the swc as a library reference).
This way, Flash only has to compile your code and simply takes the already compiled images from the swc. It then should compile much faster.
ctrl+enter, that will compile all things in library and the AS code.
most situation that use just change little things, and then compile it.
it would waste much time that no need to waste.
you can export some thing that would not always be changed to SWC file, and to to publish setting,
add SWC file into your Fla. or move you Fla project to Flash build, compile use less time more than in flash ide.