riaxe snippets
Archive for February, 2012
Run Flex/AIR Mobile app in the background
Feb 11th
Running a Flex Mobile application in the background for iOS and Android is explained below as per adobe:
iOS background behavior [Not Supported]
On iOS, applications are not permitted to run in the background in a generic fashion. Instead, they must declare that they want to perform a certain type of background processing, such as keeping a voice-over-IP call going or completing a pending upload.
AIR does not provide support for this iOS background processing model, so when they are sent to the background, AIR apps are simply paused. Their framerate goes to zero, no events are dispatched, and no rendering occurs. They do, however, stay resident in memory by default. This allows the application to preserve its state when brought back to the foreground.
Android background behavior [Partially Supported]
On Android, applications are encouraged to do as little as possible in the background but do not have severe restrictions imposed. When an AIR application is sent to the background on Android, its animation framerate is reduced to four frames per second and, although all events continue to be dispatched, the rendering phase of the event loop is skipped.
AIR apps on Android therefore can continue to perform background tasks, such as completing an upload or download operation, or periodically syncing information. However, applications should take steps to further reduce their framerate, turn off or reduce other timers, and so on, when in the background.
Reference: http://www.adobe.com/devnet/air/articles/considerations-air-apps-mobile.html
APN using Flex Mobile in Windows – Native Extensions – iOS Build Issues [Solved]
Feb 10th
Its always difficult developing iOS apps on Windows as we don’t have access to the native stuff. While using Native Extensions for iOS devices we often miss-configure the application xml.
I used the example application for using Apple Push Notifications mentioned here – http://flashsimulations.com/2011/12/16/apple-push-notification-service-native-extension-for-adobe-air/
We need to follow the following steps in order to use Native Extensions for iOS on Windows using Flash Builder 4.6 and AIR 3.1:
- We need to add the app id configured in apple’s developer portal.
<!– A universally unique application identifier. Must be unique across all AIR applications.
Using a reverse DNS-style name as the id is recommended. (Eg. com.example.ExampleApplication.) Required. –>
<id>com.riaxe.testapp</id>
- We need to copy the Entitlements present in the pList file from the mobileprovision file
We can get the Entitlements from the mobileprovision file that we use. We can get the mobileprovision file from the apple’s developer portal.
We can copy the XML from the file under Entitlements section.
<key>Entitlements</key>
<dict>
<key>application-identifier</key>
<string>LACP5QKG47.com.riaxe.testapp</string>
<key>get-task-allow</key>
<true/>
<key>keychain-access-groups</key>
<array>
<string>LACP5QKG47.*</string>
</array>
</dict>
- We need to add the Entitlements XML structure onto the Application XML
<iPhone>
<Entitlements>
<![CDATA[
<key>application-identifier</key>
<string>LACP5WER47.com.riaxe.testapp</string>
<key>get-task-allow</key>
<true/>
<key>keychain-access-groups</key>
<array>
<string>LACP5WER47.*</string>
</array>
]]>
</Entitlements>
<InfoAdditions><![CDATA[
<key>UIDeviceFamily</key>
<array>
<string>1</string>
<string>2</string>
</array>
]]></InfoAdditions>
<requestedDisplayResolution>high</requestedDisplayResolution>
</iPhone>
Done!!! This would definitely fix build issues in Flash Builder 4.6 for iOS devices.
Flex Viewstack initializing dynamic child issue [Solved]
Feb 10th
We often use a viewstack component to display stacked UI elements.
When we add components using MXML we often don’t face any issues related to the indexing.
<mx:ViewStack>
<mx:Panel id=”panel1″/>
<mx:Panel id=”panel2″/>
</mx:ViewStack>
But when we try adding the components at an index using Actionscript we often face issues with the initialization of the child view components.
private function addViewAtIndex(index:Number):void
{
var pnl:Panel= new LoaderPanelCanvas();
addChild(pnl);
}
I found a workaround to this. I extended the Canvas to create a custom component with all the related properties as shown below:
public class SlideViewStack extends Canvas
{
public function SlideViewStack()
{
initialise();
}
private var _selectedIndex:Number = -1;
public function get selectedIndex():Number
{
return _selectedIndex
}
public function set selectedIndex(value:Number):void
{
if(_selectedIndex == value)
return;
_selectedIndex = value;
if(this.numChildren > 0)
showSelectedChild();
}
private function showSelectedChild():void
{
for(var i:int = 0; i < this.numChildren; i++)
{
getChildAt(i).visible = false;
}
getChildAt(_selectedIndex).visible = true;
}
}
Hope it helps
Simple Touch Drag/Gesture Pan using AS3 TouchEvents
Feb 8th
Had some difficulties using the Gesture event panning. It didn’t work in most of the cases. Fixed the panning/dragging issues using touch events instead.
//Use this on initialisation
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
//Image Component with touch event
<s:Image id=”image” x=”203″ y=”380″ source=”@Embed(‘assets/image.png’)” touchBegin=”onTouchBegin(event)”/>
//Image pan on touch begin
protected function onPan(event:TransformGestureEvent):void
{
image.x += event.offsetX;
image.y += event.offsetY;
}