_AIR TIPS その3
- 2010-01-17(日)
- AIR,
- ActionScript,
- Flash

今回はAIRでの画面解像度の取得方法について、解説しようと思います。
画面解像度が取得できれば、アプリを任意の場所に配置することができます。
画面解像度が取得できれば、アプリを任意の場所に配置することができます。
画面解像度の取得方法
画面解像度を取得するには、Screen.mainScreen.visibleBoundsというプロパティが用意されていて、以下のようにしてサイズを取得することができます。
Screen.mainScreen.visibleBounds.width = コンテンツを使用できる領域の横サイズ
Screen.mainScreen.visibleBounds.height = コンテンツを使用できる領域の縦サイズ
Screen.mainScreen.visibleBounds.x = Macの場合だとドック領域のサイズ
Screen.mainScreen.visibleBounds.y = Macの場合だとメニューバーやドック領域のサイズ
Screen.mainScreen.visibleBounds.right = width + x
Screen.mainScreen.visibleBounds.bottom = heigth + y
Screen.mainScreen.visibleBounds.size =(x=width, y=height) 戻り値はPoint
ですので、画面解像度は「Screen.mainScreen.visibleBounds.width + Screen.mainScreen.visibleBounds.x」で取得できます。
※以下は、自身のMacBook(10.6/1280×800)で調べた結果です。(ドックは右位置で、通常は隠してあります。)
環境によっては、xの値(もしかしたらyの値も)が上手く取得できない場合があるかもしれませんが、アプリの配置ではwidthとheightの値を取得すれば良いと思います。
参考:
Screen - HTML デベロッパー用 AIR 言語リファレンス
仮想デスクトップのサイズ計算 | デベロッパーセンター
Screen.mainScreen.visibleBounds.height = コンテンツを使用できる領域の縦サイズ
Screen.mainScreen.visibleBounds.x = Macの場合だとドック領域のサイズ
Screen.mainScreen.visibleBounds.y = Macの場合だとメニューバーやドック領域のサイズ
Screen.mainScreen.visibleBounds.right = width + x
Screen.mainScreen.visibleBounds.bottom = heigth + y
Screen.mainScreen.visibleBounds.size =(x=width, y=height) 戻り値はPoint
ですので、画面解像度は「Screen.mainScreen.visibleBounds.width + Screen.mainScreen.visibleBounds.x」で取得できます。
※以下は、自身のMacBook(10.6/1280×800)で調べた結果です。(ドックは右位置で、通常は隠してあります。)
trace(Screen.mainScreen.visibleBounds.width);//1276(ドック表示時:1230) trace(Screen.mainScreen.visibleBounds.height);//778 trace(Screen.mainScreen.visibleBounds.x);//0 trace(Screen.mainScreen.visibleBounds.y);//22 trace(Screen.mainScreen.visibleBounds.right);//1276 trace(Screen.mainScreen.visibleBounds.bottom);//800 trace(Screen.mainScreen.visibleBounds.size);//(x=1276, y=778)ドックの表示・非常時でwidthの取得する値が変化するみたいですが、xの値が正しく取得できませんでした。
環境によっては、xの値(もしかしたらyの値も)が上手く取得できない場合があるかもしれませんが、アプリの配置ではwidthとheightの値を取得すれば良いと思います。
参考:
Screen - HTML デベロッパー用 AIR 言語リファレンス
仮想デスクトップのサイズ計算 | デベロッパーセンター
このエントリーをTwitterでつぶやく (投稿画面に飛びます)
- Newer: _1,000ツイート達成
- Older: _Flashに配列形式のデータを渡す





