ActionScript / AIR - defining device profile at runtime?

I am developing an application for desktop and mobile devices and would like to use the same code base for each assembly.

I want to use cacheAsBitmapMatrixfor some of my display objects, but it cacheAsBitmapMatrixthrows an error if it is included in an AIR application with a device profile other than mobileDevice or extendedMobileDevice.

something like the following would be ideal:

if (cacheAsBitmapMatrix.isSupported)
   myDisplayObject.cacheAsBitmapMatrix = new Matrix();

using try / catch:

try                {myDisplayObject.cacheAsBitmapMatrix = new Matrix();}
catch(error:Error) {}
finally            {myDisplayObject.cacheAsBitmap = true;}

update:

with the exception of television profiles, this should also work to distinguish between mobile and desktop:

//Resoslve Profile
if  (Capabilities.os.indexOf("Windows") > -1 || Capabilities.os.indexOf("Mac") > -1 || Capabilities.os.indexOf("Linux") > -1)
    trace("Desktop Profile");
    else
    trace("Mobile Profile");

update 2:

seems like the easiest way, and perhaps the most common way to determine the profile at runtime is to call:

NativeWindow.isSupported;

flash.display.NativeWindow :

AIR: , AIR . , NativeWindow.isSupported. AIR API .

3:

BlackBerry PlayBook NativeWindow. , , . , :

if  (
    (Capabilities.os.toLowerCase().indexOf("mac") == -1) &&
    (Capabilities.os.toLowerCase().indexOf("windows") == -1) &&
    (Capabilities.os.toLowerCase().indexOf("linux") == -1)
    )
    deviceIsMobile = true;
+3
2

document . cacheAsBitmapMatrix , . try/catch.

: , "check once":

public class Capabilities2
{
    private static var cacheAsBitmapMatrixChecked:Boolean;
    private static var cacheAsBitmapMatrixStatus:Boolean;

    public static function get cacheAsBitmapMatrixIsSupported():Boolean
    {
        if (cacheAsBitmapMatrixChecked) return cacheAsBitmapMatrixStatus;
        var test:Sprite = new Sprite();
        try
        {
            text.cacheAsBitmapMatrix = new Matrix();
            cacheAsBitmapMatrixStatus = true;
        }
        catch (error:Error)
        {
            cacheAsBitmapMatrixStatus = false;
        }
        cacheAsBitmapMatrixChecked = true;
        return cacheAsBitmapMatrixStatus;
    }
}

, , . "": , , , :)

+2

, , "Capabilities.playerType"

if (Capabilities.playerType == "Desktop") {
    trace ("running on mobile");                
}
else {
    trace ("running on web");
}
-2

All Articles