I use FlashDevelop (great and free alternative to Flash Builder) that uses the (latest) open source Flex framework of Adobe.
I want to develop an app for Android and iOS as well. In some parts I use an StageWebView to display content that i don’t want to rewrite to flex AS3 code.
In a nutshell: I am in an early stage of development and this is my first flex mobile app. In some parts it uses the HTML5 feature ‘localStore’ (part of object window in javascript) to store some data. But it seems that this feature is not available in the webkit browser of flex? I also want to know if this is a typical flex problem or does it also exists when the app will be deployed? The problem does not occur when loading the HTML part on a mobile device (for example in mobile safari).
Also when the localStorage feature is not available it will switch back to cookies. But this is also not working correctly. In all other browsers no problemo, even in IE.
Result of cookie: varname=undefined; expires=Thu, 03 May 2012 01:01:41 GMT.
What is going on?
Here is some Javascript code:
// Picked up from: https://github.com/carhartl/jquery-cookie
// Usage: http://www.electrictoolbox.com/jquery-cookies/
jQuery.cookie = function (key, value, options) {
// key and at least value given, set cookie...
if (arguments.length > 1 && String(value) !== "[object Object]") {
options = jQuery.extend({}, options);
if (value === null || value === undefined) {
options.expires = -1;
}
if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}
value = String(value);
return (document.cookie = [
encodeURIComponent(key), '=',
options.raw ? value : encodeURIComponent(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}
// key and possibly options given, get cookie...
options = value || {};
var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
Local storage:
jQuery.locstore = function(key, val, opt ) {
var ls = window.localStorage,
j = window.JSON,
b = !( !ls || !j );
if( !b )
{ return jQuery.cookie( key, val, opt ); }
// set
if( arguments.length > 1 )
{
var bRem = (val == null ),
v = (bRem || typeof val == 'number' || typeof val == 'string')?val:j.stringify(val);
if( bRem )
{ b = ls.removeItem(key); }
else { b = ls.setItem(key, v); }
return b;
}
// get
var v = ls.getItem(key);
if( v != null && typeof val != 'number' )
try { v=j.parse(v); } catch(e){}
return v;
};
I ask it here because i didn’t find an answer on the net. Maybe someone give me a clue into the right direction to solve this?
There is no webkit browser in the Flex Framework.
A version of Webkit is included in Desktop AIR runtime; but that won’t matter for mobile applications.
Mobile AIR uses the underlining browser engine of the OS (Android or iOS) for StageWebView. I’m not sure of specifics; nor what functionality is exposed via the “Browser in the app” but here is a quote from the docs to confirm this:
So, I surmise that your issue has nothing to do with Flex, nor AIR, but rather the support of the browser in the OS you’re testing on.