Air for android ignores external swf files - android

I am working on some app that loads external swfs from the application directory
the problem is that some swf files get loaded correctly and others give ioerror url not found
i put the paths in an array and use a loader to load the path
var arr:Array = ["Games/1.swf", "Games/2.swf"];
var loader:Loader = new Loader();
loader.load(new URLRequest(arr[0]));
this is just example and it is the same in loading all the files but does not work on all files.
what would be the problem?

Firstly, whenever you load something, listen for the appropriate error events so you know what's going on:
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
When using mobile, you should use the app:// shorthand as a reference to the application directory (which I assume is where your Game folder is. Relative paths do not usually work.
So it should look like this:
var arr:Array = ["app://Games/1.swf", "app://Games/2.swf"];
For more information/options, you can look at my answer to this question

Related

Where should I put static text file?

I wanna include a text file to my project in smartface appstudio. I put it where? In resources folder or assets? FileStream could not read it in resources (as a drawable item). Any idea?
var txtFile = new SMF.IO.FileStream(SMF.IO.applicationResources, "words.txt", SMF.IO.StreamType.read);
txtFile.readToEnd();
It is not implemented in current release of Smartface App Studio. Also I have tried it before. It is Phase 2 for File Operations.
You can download your static text file from the internet and can save it to the local storage. And read it from there. I can just suggest you this idea. Check some helpful links below.
http://developer.smartface.io/hc/en-us/articles/203177557-File-Operations
http://developer.smartface.io/hc/en-us/articles/202153536-File-Download-Upload

Titanium 3.X getFile() from local storage

Using Titanium on Android 4+ I want to access a jpeg file which has been taken with the camera. I need to achieve 2 objectives, namely, return the EXIF data and transfer the bytes to an API endpoint. My problem is I'm unable to access the file...
I'm using a 3rd party module to handle the file selection (Multi Image Picker) which returns a list of file locations, using the File Manager app on the emulator (GenyMotion) I can confirm the location on disk is correct. However, the following always returns false...
var file = Ti.Filesystem.getFile('/mnt/sdcard/DCIM/Camera/IMG_20140901_083735.jpg');
Ti.API.info('Do we have a file? ' (file.exists()? 'YES' : 'NO'));
The output for the above would be... Do we have a file? NO
Further reading shows Titanium has 5 predefined folder locations which can be passed into the getFile() method and one possible reason for the above code not working would be it is defaulting to the 'Resouces' folder location? That said all but one folder location is app specific, the exception being externalStorageLocation. Now my understanding of an Android device is that any image taken with the camera will be stored on the internal storage system unless an SD card is present. This is true in my case as the following lists 0 files...
var extDir = Ti.Filesystem.getExternalStorageDirectory();
var dir = Ti.Filesystem.getFile(extDir);
var dir_files = dir.getDirectoryListing();
Ti.API.info('External files... ' + dir_files.length);
The output for the above would be... External files... 0
So am I right in thinking Appcelerator have simply not included the ability to access local storage (outside of any app specific folders) within their API? Or am I missing something and there is in fact another way?
Thanks to #Bharal I was able to find a solution...
By using the Ti.Media.openPhotoGallery() method I was able to identify the correct native path for the image by inspecting the event object returned from the success callback.
The path was missing 'file://' at the beginning, I couldn't be 100% sure but I suspect this forces the getFile() method to use an absolute path and not a relative path from within the Resources folder.
To confirm, the following will return a file object...
var file = Ti.Filesystem.getFile('file://[path]');
Where [path] is the folder location as reported within the File Manager app on the device, for example '/mnt/sdcard/DCIM/Camera/IMG_20140901_083735.jpg'
Yah mon, i dunno.
Here is wat i used when i was doin pictures on my Ti app, but then i got rid of that section because i realised i didn't need to be doin pictures. Pictures mon, dey ain' what you want sometimes, yo?
Ti.Media.openPhotoGallery({ //dissall jus' open up a piccha selectin' ting. ez.
success:function(event){
var image = event.media;
if (event.mediaType==Ti.Media.MEDIA_TYPE_PHOTO){
//so image.nativePath is the path to the image.
// profileImg be jus' some Ti.UI.createImageView ting yo be puttin in yo' page.
//meyybe yo be wantin' alert(image.nativePath); here too, dat be helpin?
profileImg.image = image.nativePath;
}
},
cancel:function(){
//we cancelled out, why we doin' that?
}
});
Now that isn't going to really be helpin' you, but yo can use that to see wat the native path yo piccha be usin' be, and then be seein' if maybe what yo be puttin' in yo code be sam ting.
Jus' wrap the above as an addEventListener("click", function(){ ... } ); on sam ting in yo page, and jus' add sam element to put th' piccha in if yo be wantin' to see the piccha but i be tellin' you picchas mon, sometimes dey ain' worth time.
But meyybe yo wantin' use not an emulator for dis ting, dey can be actin' weird yo should be usin some small phone maybe? Dat way you can be findin' if yo got dem memory leeks and meyybe some memory sprouts, an memory onions too.

Load an external text. Works on my computer, but not on app

I'm creating an app for Air 3.8 on Flash CS6. When I click on info_btn, the programm load an external textfile (here test.txt) and shows it in my dynamic text field (here info_txt).
It works when I CRTL+Enter, but not on my android device when I test the .apk file I created. I'm sure the reason is that the test.txt is not compiled in the apk, but I don't know how to change that. If you guys can help, it would be great.
Here is my code, if it can help:
var fl_TextLoader_3:URLLoader = new URLLoader();
var fl_TextURLRequest_3:URLRequest = new URLRequest("textes/test.txt");
fl_TextLoader_3.addEventListener(Event.COMPLETE, fl_CompleteHandler_3);
function fl_CompleteHandler_3(event:Event):void
{
var textData:String = new String(fl_TextLoader_3.data);
info_txt.text = textData;
}
info_btn.addEventListener(MouseEvent.CLICK, fl_infotxt);
function fl_infotxt(Event:MouseEvent):void {
fl_TextLoader_3.load(fl_TextURLRequest_3);
}
Usually mobile AIR projects will have an assets folder -- they do in Flash Builder and Flash Develop IDEs, so I assume CS6 has something similar.
The assets folder is where images and app icons go that will be delivered in the .apk. You can put any files and folders you want in there, including your text files. To package your text file into the .apk, you could create a assets/textes folder and put your test.txt in it.
Then the URL you would need in your code would be:
var fl_TextURLRequest_3:URLRequest = new URLRequest("assets/textes/test.txt");

Adobe Flex AIR download videos in Android device

I want to download a set of video files to a default folder path in an Android device and then have access to the path and files. The FileReference class does not support this features. Is there another way? Thank you.
I dont use file reference at all. I use a Loader to download the file. I then create a new File object with the path where I want to save the file, and use a FileSteam to write the data from the loader to the file.
var req:URLRequest = new URLRequest(url);
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, handler);
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.load(req);
function handler(e:Event):void{
var file:File = new File(path);
var stream:FileSteam();
steam.open(file, FileMode.WRITE);
steam.writeBytes(loader.data);
steam.close();
}
something like this should accomplish what you are looking for. I wrote this code from memory so it may not be exactly correct but should be good enough to get you going. Make sure you put this in a try/catch since file and filesteam both throw exceptions

AS3 Air On Android - Load SWF as its own Main()

I'm using a wrapper app to download a remote SWF and save it to a Xoom Tablet. The download and save works fine but using something like
var file:File = File.applicationStorageDirectory.resolvePath("app.swf");
var loader:Loader = new Loader();
loader.load(new URLRequest(file.url)/*,context needed?*/);
_main.addChild(loader);
Screws with the targeting in the loaded swf so that in my loaded swf if I try and call "stage" from "Main" its null. I thought since loaded SWF's had there own sandbox it would load and run just like it I installed it by its self, does not seem to be the case. If this was a desktop app I could use NativeWindow but its not supported on mobile devices yet. Are there any know options where I can load and run it in its own sandbox where paths and roots are intact? Possibly a command it launch it as a separate swf from my wrapper swf?
I ran into more issues but finaly found the correct way, you cant acceess "File" but this works just fine.
function getSWF():void
{
var request:URLRequest = new URLRequest("child.swf");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadHandler);
loader.load(request);
_main.addChild(loader);// _main is my display sprite
}
function loadHandler(event:Event):void
{
var childSwf:Object = event.target.content;
childSwf.init( PARAMS );// in my case I needed to pass XML but this is any method in the Main of the child swf, note that "stage" is read only, so your parent swf needs to set any stage vars you need
}

Categories

Resources