Adobe AIR 3.8 Flash Builder 4.6 for iOS - Secondary SWF with Actionscript works on fast packaging but fails on Releast Build - ios

I have a simple Flex Mobile project that just allows user to swap between 2 different .swf games. I load the .swf with the following code:
private function loadFile(f:String):void{
var _urlRequest:URLRequest = new URLRequest(f);
var _loader:Loader = new Loader();
var _lc:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSWFLoaded);
_loader.load(_urlRequest, _lc);
txt.text="loading";
// add loader to container
grp.addChild(_loader);
}
private function onSWFLoaded(e:Event):void {
// status text to show it loaded
txt.text="loaded!";
}
Then on user button click I just do:
loadFile("file1.swf");
file1.swf is packaged into the build. I run this on debug under fast packaging on my iPod Touch and everything works like a charm, but when I do an export release build, my status text still says "loaded", but the swf loads very strangely - as if there's some code that is failing to run properly.
Since it works on fast packaging with no issue, what would be the difference between release build and fast build that can cause code in child swfs to fail?
Any ideas would be appreciated.
Thanks.

Solved the issues based on comments from here:
http://forums.adobe.com/message/5398137
Using var file:File = File.applicationDirectory.resolvePath("file1.swf"); and adding the Flex Compiler option "swf-version=19" fixed the issue for me. Not sure which one of the two changes fixed it but it all works now.

Related

How to copy from Storage to FileSystemStorage in Codenameone and display in BrowserComponent

I've been reading a lot of StackOverflow posts that discuss copying data from FileSystemStorage to Storage in CodenameOne, such as described in this answer from Shai, as seen below:
InputStream stream =
FileSystemStorage.getInstance().openInputStream(i);
OutputStream out =
Storage.getInstance().createOutputStream("MyImage");
Util.copy(stream, out);
Util.cleanup(stream);
Util.cleanup(out);`
I've been trying to do the reverse: save from Storage to FileSystemStorage in order to show a PDF in the BrowserComponent (while using iOS), but have not been able to do so. I need to show the PDF within the app (so I don't want to use Display.getInstance().execute()).
Basically, I'm trying to dynamically populate a Container with whatever files the user selects-- I am using the FileChooser library for CN1 from Steve Hannah. (Disclaimer: I have made slight modifications to this library as it used in the app I'm working on-- HOWEVER, when I choose images with this library and pull them from Storage to an Image via InputStream, they display perfectly in an ImageViewer so I know that all files are being saved correctly in Storage.)
Here is my code (with help from Steve Hannah's comment on GitHub):
//fileLocation and fileName are slightly different but both end with file extension
File file = new File(fileToUpload.getFileName());
FileSystemStorage fss = FileSystemStorage.getInstance();
InputStream is = Storage.getInstance().createInputStream(fileToUpload.getLocation());
OutputStream os = fss.openOutputStream(file.getAbsolutePath());
Util.copy(is, os);
ToastBar.Status status = ToastBar.getInstance().createStatus();
String message = file.exists() + " " + file.isFile() + file.getAbsolutePath();
status.setMessage(message);
status.setExpires(3000);
status.show();
NativeLogs.getNativeLogs();
if (Display.getInstance().getPlatformName().equals("ios")) {
//Log.p("in ios !!!!");
BrowserComponent browserComponent = new BrowserComponent();
browserComponent.setURL(file.getPath());
horizontalContainer.add(browserComponent);
}
The ToastBar displays true and true for file.exists() and file.isFile().
I stipulate iOS because as far as I've seen while researching previewing PDFs within an app, I've seen that Android needs to have a different implementation, like adding a NativeInterface with an Android library. I also saw in different answers on the Google Group that this functionality (using browserComponent to view PDFs) is only available for iOS and not on the simulator. In the simulator, I see a blank space. My iPhone just freezes and/or crashes after displaying the ToastBar (and I work on a Windows machine, so not much ability to see native logs....)
What can I do to access the file and show it in the BrowserComponent?
Thank you!
Simple solution -- the file had a space in it (eg. "Test page.pdf") and didn't show! When I used files that didn't have spaces this worked and after removing spaces in the file names, thankfully everything worked. I'll have to add code to handle this scenario.
Thanks for your help!

Adobe air on iOS - FileReference Download Error

When I use the Download method of the FileReference class, everything works fine on Desktop and Android, but I get an error on iOS.
This is the code:
var req = new URLRequest(url);
var localRef:FileReference = new FileReference();
localRef.download(req);
On iOS I'm getting an Alert:
Download Error
File downloads not supported.
I already tried to NavigateToUrl() and it asks save the file in Dropbox or another App.
How can I fix this error?
You shouldn't use FileReference on mobile (or AIR, in general, though it does open the Load/Save dialog on desktop so there can be some use there). You should instead use File and FileStream, which give you far more control over the file system.
In this case, you could try to use File.download() and save it to File.applicationStorageDirectory, but I don't know if it will have any difference since it extends FileReference.
What I generally do is use URLStream instead of URLLoader. It gives you access to the raw bytes of the file you are downloading and then use File and FileStream
So something like (and this is untested off the top of my head, though I have used similar in the past):
var urlStream:URLStream = new URLStream();
urlStream.addEventListener(Event.COMPLETE, completeHandler);
urlStream.load(new URLLoader('url');
function completeHandler(e:Event):void {
var bytes:ByteArray = new ByteArray();
urlStream.readBytes(bytes);
var f:File = File.applicationStorageDirectory.resolvePath('filename');
var fs:FileStream = new FileStream();
fs.open(f, FileMode.WRITE);
fs.writeBytes(bytes);
fs.close();
}
Now, obviously, there is a lot more you want to account for (errors, progress, etc). That should be enough to point you in the right direction, however.
It's possible to create a full download manager using this method (something I did for an iOS project two years ago), since you can save as-you-go to the file system rather than waiting until Event.COMPLETE fires (using the ProgressEvent.PROGRESS event). That allows you to avoid having a 500MB file in memory, something most devices can't handle.

App used to work with AIR 3.2, doesn't work with AIR 3.5

I'm getting this error when I press a button in a flash/air app that used to work in the AIR 3.2 SDK - now upgraded to the AIR 3.5 SDK. Any help much appreciated.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at seed_template_fla::MainTimeline/frame7()[seed_template_fla.MainTimeline::frame7:31]
at flash.display::MovieClip/gotoAndPlay()
at seed_template_fla::MainTimeline/gotoPage() [seed_template_fla.MainTimeline::frame1:20]
at seed_template_fla::MainTimeline/gotoRepro() [seed_template_fla.MainTimeline::frame1:12]
I'm creating an app for iPhone using Flash CS6 on Mac and exporting using the Air 3.5 SDK. I also have the AIR 3.5 runtime installed.
The app is very simple at the moment. It basically moves from frame to frame when you press a button using the gotoAndPlay(frameNr) function. There are some hexes on the frames that update an array of numbers when clicked. They are also toggled visible/not visible.
This used to work perfectly using the AIR 3.2 SDK, but I recently downloaded the AIR 3.5 SDK from adobe and added it through flash (Help>Manage Air SDK) and set it as the build target in File>Publish Settings>Target.
When I switch back to AIR 3.2 SDK, the app works perfectly again.
Also, when I upload the app to my iPhone 4S running IOS 5.1 using AIR 3.5 SDK, I just see a black screen with 5 loading dots flashing. This also works fine with AIR 3.2 SDK.
This is the code for frame 7
The last line is line 31.
stop();
techtitle.text = "Select Trait";
techdesc.text = "Spend points to change core stats and other special abilities";
points.visible = false;
techpoints.visible=false;
pointsbalance.text = myPoints.toString();
btn_tech.visible = false;
curTechSelected = null;
trace("set hexes invisible");
for (var j:int = 0; j <= 67; j++) {
if (hexStatusb[j] == 1) {
this["btn_hex_"+j+"b"].visible = false;
}
}
function onBtnHex37bClick(event:MouseEvent):void
{
techtitle.text = "tech1";
techdesc.text = "tech1 description"
techpoints.text = "-2";
points.visible = true;
techpoints.visible=true;
btn_tech.visible = true;
curTechSelected = btn_hex_37b;
curTechSelectedNr = 37;
curTechPoints = 2;
}
trace(this["btn_hex_37b"]);
btn_hex_37b.addEventListener(MouseEvent.CLICK, onBtnHex37bClick);
OK - so, after trying out lots of things, I figured out why this is happening.
Solution: get rid of all TFL text objects when running AIR 3.5 SDK
It seems that the TFL Text library wasn't being loaded properly at runtime. Something crucial that I neglected to mention was that I was getting this warning message (similar here http://forums.adobe.com/thread/825637)
Content will not stream... The runtime shared libraries being preloaded are textLayout_1.0.0.05... TFLText
and this warning message in the output
Warning: Ignoring 'secure' attribute in policy file from http://fpdownload.adobe.com/pub/swz/crossdomain.xml. The 'secure' attribute is only permitted in HTTPS and socket policy files.
Simply removing all TFLText objects and changing them to classic text makes the app work fine again.
#csomakk Great news. I have found the answer. You can publish in 3.5 and 3.6 and have your TLF Text too. I posted a write-up on my blog that shows exactly how to do it.
To get started: the error message states that something is null.. it means, that the program doesn't know, where to look for it. It can happen, when you didn't create the object (btn_hex_37b = new MovieClip()); or you haven't even created a variable for it.
on the given line (btn_hex_37b.addEventListener(MouseEvent.CLICK, onBtnHex37bClick);) only btn_hex_37b can be null, because onBtnHex37bClick exists, and if it wouldn't, the program wouldn't compile.
The reason it came up when switching to AIR 3.5 is probably that it calls some creation functions in different order. Go to the line where you define the btn_hex_37b variable. Search for that functions calling.. Make sure, that btn_hex_37b is created before going to frame7.
Also, if its not a vital, to have onBtn_hex_37bClick, you can do the following:
if(btn_hex_37b){
btn_hex_37b.addEventListener(MouseEvent.CLICK, onBtnHex37bClick);
}
the if will check if btn_hex_37b is not null.
On the else method, you can give a timeouted method(but that is ugly), or give the eventlistener right after the creation of the object.
Hope this helped.
For Flash CS6, copy this swc:
/Applications/Adobe Flash CS6/Common/Configuration/ActionScript 3.0/libs/flash.swc
Into my Flash Builder project using these steps:
http://interactivesection.files.wordpress.com/2009/06/include_fl_packages_in_flex_builder-1.jpg
and then use this link
http://curtismorley.com/2013/03/05/app-used-to-work-with-air-3-2-or-3-4-doesnt-work-with-air-3-5-or-3-6/#comment-241102

How to Reduce AIR app file size?

I've uploaded an AIR-built .ipa file to Apple. From Apple: "The app binary listed below was 8 MB when you submitted it, but will be 20 MB once processed for the App Store"
So I'm trying to trim it. I've gotten rid of all unused .as classes and all unused assets. Does anyone have any clever way of reducing file size further? One way I thought of is this:
If in class A I have:
[Embed(source="assets/newButtons/purple/purpleHomeSmall.png")]
and then I re-embed it in class B with the same code, does that mean it is embedded twice with twice the file size? If so, how would I embed it in one class but have access to it in other classes?
Edit: I've discovered that if you have assets in your project that you don't use, the compiler STILL ADDS them. So you have to get rid of them before making a release build.
Instead of embedding the source why not just load it from URI at runtime?
Create an abstract bitmap class that builds a bitmap from the URI and places it on stage.
This way you can ensure the bitmap is only stored once and is loaded lazily.
Update
you can add a folder in the air for iOS settings dialog.
Place the images you want and then:
var imageLoader:Loader = new Loader();
var theURL:String = "string to your uri can be local or web";
var imageRequest = new URLRequest(theURL);
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
imageLoader.load(imageRequest);
function onComplete(evt:Event)
{
addChild(imageLoader.content);
}
One option i have used is to compile the ipa with only the most necessary assets and then when the user first initializes the app have it download and store further assets in the application storage (this could be done with a single zip-file and the FZip class: http://codeazur.com.br/lab/fzip/)
This way the app only has to download the assets once (on first run) and they are immediately available in the future from the local system.
Instead of embedding images in each source file, what I do is create a class in the default package, where I place all my images as static public variables. Something like this:
package {
public class Icons{
[Embed(source="assets/icon1.png")] [Bindable] static public var icon1:Class;
}
}
Whenever I need the icon, I just use Icons.icon1.
You cannot ! Your app will be more than 20Mb and its like that. Because the need of Adobe AIR runtime, embedded in your IPA.
So its useless to try to optimize your code, asset .... should chase adobe for this job !
My application: prestadget is 800Ko as APK (w/o AIR runtime) but 21Mo as IPA ;-( same code

How to do iPad flash app debugging on Windows? [duplicate]

This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
Debugging iOS/AIR content on the device
I'm porting my Air app to iPad. I compiled it with:
adt -package -target ipa-ad-hoc -storetype pkcs12 -keystore store.p12 -storepass ****** -provisioning-profile profile.mobileprovision app.ipa app.xml app.swf
App was deployed on device through iTunes. When I launch app on iPad I get a black screen. Looks like some exception is thrown or something like that. How can I see that exception? Or if to be more general, how do you guys debug iOS app on Windows?
As far as my knowledge goes there is no remote debugging with AIR and iOS possible. So you have to revert to creating a scrolling text field somewhere and show log/debug texts there.
Edit: See Debugging iOS/AIR content on the device.
Edit2: Short tutorial video on debugging on iOS via Flash Prof CS5.5: http://www.youtube.com/watch?v=DanNBN89uhs
You can use the uncaughtErrorEvents property (found in your main documents loaderInfo property) to catch any unhandled error and show it also in the text field (see http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/LoaderInfo.html#uncaughtErrorEvents)
There is also the possibility to define compiler constants to enclose debug log statements within actionscript so you can easily turn them on and off.
I normally also test first the application on my windows before creating an iPad version of it.
Final tip: remember that only your main swf can contain actionscript.
Edit:
Here is a example, try to add this code before any other actionscript is executed:
import flash.events.UncaughtErrorEvent;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldType;
// ...
// textLog contains errors
var textLog: TextField;
// make sure there is a uncaughtErrorEvents property (in case of older player)
if (this.loaderInfo.hasOwnProperty('uncaughtErrorEvents'))
{
// listen for uncaught error events
this.loaderInfo['uncaughtErrorEvents'].addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, handleUncaughtError);
// make sure text field stays on top
this.addEventListener(Event.ENTER_FRAME, handleEnterFrame);
// create TextField at bottom using 1/5th of stage height
textLog = new TextField();
textLog.width = this.stage.stageWidth;
textLog.height = Math.floor(0.20 * this.stage.stageHeight);
textLog.y = this.stage.stageHeight - textLog.height;
textLog.multiline = true;
textLog.wordWrap = true;
textLog.defaultTextFormat = new TextFormat('_sans', 10);
textLog.type = TextFieldType.DYNAMIC;
textLog.background = true;
textLog.backgroundColor = 0xCCCCCC;
this.addChild(textLog);
textLog.appendText('Catching errors\n');
}
// show error and scroll to bottom line
function handleUncaughtError(anEvent: UncaughtErrorEvent): void
{
textLog.appendText(anEvent.error + '\n');
textLog.scrollV = textLog.maxScrollV;
}
// make sure textLog stays on top of all other children
function handleEnterFrame(anEvent: Event): void
{
if (this.getChildIndex(this.textLog) != this.numChildren - 1)
{
this.addChild(this.textLog);
}
}
Are you using Air 2.7 or 3.0? I had this issue when I was using a library built with alchemy. For some reason using the alchemy library caused a blank screen. Remote debugging didn't help me either because it was before everything. I fixed it by not including the alchemy library (the library was for fast JSON parsing)

Resources