How to tell if your user is on a Mac in ActionScript 3
Posted by Ian Serlin | Tweet This | Filed under Actionscript 3, problem solution
Ok, so the real problem here is that the Adobe Flash Player plug-in for the Mac has horrible performance issues (read: sucks) compared to its PC counterpart for reasons easily justified yet still incredibly painful for Flash/Flex developers. In this case, especially if you are doing anything with the Microphone, Camera or Video classes you may want to gracefully degrade the experience so that your user’s laptop doesn’t burn their pants off when their CPU usage hits 110%.
Problem
You want to know if your swf is being loaded on a Mac.
Solution
This one’s relatively straightforward if you’ve heard of the Capabilities class, thing is I’m not sure that many people have, so here is a function to do it for you… it resides in the SystemUtil class along with a lot of other things in my code library in case you were wondering. I’m using ‘t’ and ‘f’ for clarity and not using a Boolean so I can cache the answer and call into the Capabilities class when necessary.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | package utils { import flash.system.Capabilities; public class SystemUtil { private static var _is_mac:String = ''; public static function get isMac():Boolean { if( _is_mac == "t" ){ return true; }else if( _is_mac == "f" ){ return false; }else if( Capabilities.os.toLowerCase().search( "mac" ) == -1 ){ _is_mac = "f"; return false; }else{ _is_mac = "t"; return true; } } } } |
If you know about any other performance/bug issues for Flash Player on Mac besides the above let me know in the comments because I hate nasty surprises.