MdNムック「Photoshop三ツ星テクニック大全」へグラフィック掲載いただきました

Copyright © 2010 MdN Corporation. All Rights Reserved.

2010年1月30日に MdN Corporationより発行された、MdNムック 「Photoshop三ツ星テクニック大全」へグラフィックと作業工程解説文を掲載いただきました。

月刊MdN 2008年7月号Photoshop Making Studio」掲載記事を編集いただいた内容です。P14〜P19に載っていますので、書店へ寄られた折は是非ご覧ください。

家に届いた本を手に取って見てとても嬉しく、もっと精進していかなくてはと励みになりました。今は周囲との繋がりによって生かされているが、人様の世話になるばかりではなく、そろそろ自分が人の役に立つ人間にならなくてはならない、欲を言えばこれから自分のやることがたまたま周囲に還元されるものであったりすればよいと思いました。

最近は正直あまりゆとりがないのか、(頭の中が 0と1の2色に埋め尽くされていて)何も浮かんでこないのですが、ふと気持ちが昂ぶった時や落ち着いた時などに、頭の中に浮かんだものをぽんと排出できるエネルギーを常日頃から養っていきたいです。

とにかくこのままではいかんと忙しなく動き回る日常にあって、本当に有り難い機会でした。

本誌掲載の機会をくださった出版社の方々へ、ここで改めて御礼申し上げます。

Photoshop三ツ星テクニック大全 - MdN Design Interactive

MdN Design Interactive

AS3でオブジェクトの子にあるボタンの有効/無効を切り替える「SmartButton」クラス

SmartButton

SmartButton

ActionScript3.0でオブジェクトの子にあるボタンの有効/無効を切り替える「SmartButton」クラスを作成しました。

静的クラスメンバ“enabled”は、指定したオブジェクトの [mouseChildren]と [mouseEnabled]の値を個別に設定します。操作したいオブジェクトと、ボタンの有効/無効[Boolean]を指定して使用します。

静的クラスメンバ“change”は、予め配列化したメニューと、ボタンを無効にしたい配列メニューのインデックス値を指定して使用します。指定したインデックスの子にあるボタンが無効となり、それ以外のインデックスの子にあるボタンが有効になります。

ボタンの有効/無効を切り替えるというより、厳密には指定したオブジェクトの [mouseChildren]と [mouseEnabled]の値を true/falseに切り替えます。

下記のボタンより、サンプルの閲覧およびソースのダウンロードができます。

Sample Download

【使用例】

_sp[Sprite]の子にあるボタンを無効化する


SmartButton.enabled(_sp, false);

_sp[Sprite]の子にあるボタンを有効化する


SmartButton.enabled(_sp, true);

sampleMenu[Array]の1番目のインデックスの子にあるボタンを無効化し、それ以外のインデックスの子にあるボタンを有効化する


var sampleMenu:Array = [sampleMenu1, sampleMenu2, sampleMenu3]
SmartButton.change(
sampleMenu, //配列メニュー
1, //ボタンを無効化したい配列要素のインデックス値
sampleMenu.length, //配列要素の総数
0 //配列要素の先頭
);

sampleMenu[Array]の子にある全てのボタンを有効化する


var sampleMenu:Array = [sampleMenu1, sampleMenu2, sampleMenu3]
SmartButton.clear(
sampleMenu, //配列メニュー
sampleMenu.length, //配列要素の総数
0 //配列要素の先頭
);

【パラメータ説明: “enabled”】

$scope


ボタンの有効/無効を操作したいオブジェクト
[Sprite][省略不可]

b


ボタンの有効/無効
[Boolean][省略不可]

【パラメータ説明: “change”】

buttons


配列メニュー
[Array][省略不可]

currentButtonID


ボタンを無効化したい配列要素のインデックス値
[int][省略不可]

buttonNum


配列要素の総数
[uint][規定値:0 -> 代入値:buttons.length][省略可]

indexButtonID


配列要素の先頭
[uint][規定値:1][省略可]

【パラメータ説明: “clear”】

buttons


配列メニュー
[Array][省略不可]

buttonNum


配列要素の総数
[uint][規定値:0 -> 代入値:buttons.length][省略可]

indexButtonID


配列要素の先頭
[uint][規定値:1][省略可]

ソースコード

import jp.atziluth.utils.SmartButton;


package jp.atziluth.utils{
import flash.display.Sprite;
public class SmartButton extends Sprite {
private static var buttons:Array;
private static var id:int;
private static var length:uint;
private static var index:uint;
public static function change(buttons:Array,currentButtonID:int,buttonNum:uint=0,indexButtonID:uint=1):void {
SmartButton.initialize(buttons,currentButtonID,buttonNum,indexButtonID);
SmartButton.exec();
}
public static function clear(buttons:Array,buttonNum:uint=0,indexButtonID:uint=1):void {
SmartButton.initialize(buttons,-1,buttonNum,indexButtonID);
SmartButton.exec();
}
public static function enabled($scope:Sprite,b:Boolean):void {
$scope.mouseChildren = b;
$scope.mouseEnabled = b;
}
private static function initialize(buttons:Array,id:int,buttonNum:uint,indexButtonID:uint):void {
SmartButton.buttons = buttons;
SmartButton.id = id;
buttonNum <= 0 ? SmartButton.length = SmartButton.buttons.length:SmartButton.length = buttonNum;
SmartButton.index = indexButtonID;
}
private static function exec():void {
for (var i:uint = SmartButton.index; i <= SmartButton.length; i++) {
SmartButton.enabled(SmartButton.buttons[i],i != SmartButton.id);
}
}
}
}

サンプルソースコード】

Sample.as


package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.SimpleButton;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.events.Event;
import flash.events.MouseEvent;
import jp.atziluth.gui.RelativeLayout;
import jp.atziluth.utils.AtTween;
import jp.atziluth.utils.SmartButton;
public class Sample extends MovieClip {
internal const NAVIGATOR:MovieClip=new Navigator();
private const CHANGE_MENU_NUM:uint = 4;
protected static var currentChangeMenuID:uint;
private var changeMenu:Array = [];
private var changeMenuButton:Array = [];
private var changeMenuBackground:Array = [];
private var clearMenu:MovieClip;
private var clearMenuButton:SimpleButton;
private var clearMenuBackground:Sprite;
private const ENABLED_MENU_NUM:uint = 2;
protected static var currentEnabledMenuID:uint = 1;
private var enabledMenu:Array = [];
private var enabledMenuButton:Array = [];
private var enabledMenuBackground:Array = [];
private const ROLLOVER_COLOR:uint = 0xCC3311;
private const ROLLOVER_TIME:Number = .25;
private const ROLLOVER_EASE:String = "liner";
private const ROLLOUT_COLOR:Array = [0x000000,0x666666];
private const ROLLOUT_TIME:Number = 2;
private const ROLLOUT_EASE:String = "Strong.easeInOutQuad";
private const DISABLE_COLOR:uint = 0xCCCCCC;
private const DEFAULT_COLOR:Array = ROLLOUT_COLOR;
private const REVERSE_TIME:Number = ROLLOVER_TIME;
public function Sample():void {
setStageProperty();
setStageEvent();
addNavigator();
setChangeMenu();
setChangeEvents();
setClearMenu();
setClearEvent();
setEnabledMenu();
setEnabledEvents();
switchEnabled(Sample.currentEnabledMenuID, 2, 0);
centeringLayout();
}
internal function setStageProperty():void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
}
private function setStageEvent():void {
stage.addEventListener(Event.RESIZE,onStageResizeHandler);
}
private function onStageResizeHandler(event:Event):void {
centeringLayout();
}
private function addNavigator():void {
addChildAt(NAVIGATOR, 0);
}
private function setChangeMenu():void {
for (var i:uint=1; i<=CHANGE_MENU_NUM; i++) {
changeMenu[i] =
MovieClip(NAVIGATOR.getChildByName("change" + i));
changeMenuButton[i] =
SimpleButton(changeMenu[i].getChildByName("_btn"));
changeMenuBackground[i] =
Sprite(changeMenu[i].getChildByName("bg"));
}
}
private function setChangeEvents():void {
changeMenuButton[1].addEventListener(MouseEvent.ROLL_OVER, changeMenu1RollOverHandler);
changeMenuButton[1].addEventListener(MouseEvent.ROLL_OUT, changeMenu1RollOutHandler);
changeMenuButton[1].addEventListener(MouseEvent.CLICK, changeMenu1ClickHandler);
changeMenuButton[2].addEventListener(MouseEvent.ROLL_OVER, changeMenu2RollOverHandler);
changeMenuButton[2].addEventListener(MouseEvent.ROLL_OUT, changeMenu2RollOutHandler);
changeMenuButton[2].addEventListener(MouseEvent.CLICK, changeMenu2ClickHandler);
changeMenuButton[3].addEventListener(MouseEvent.ROLL_OVER, changeMenu3RollOverHandler);
changeMenuButton[3].addEventListener(MouseEvent.ROLL_OUT, changeMenu3RollOutHandler);
changeMenuButton[3].addEventListener(MouseEvent.CLICK, changeMenu3ClickHandler);
changeMenuButton[4].addEventListener(MouseEvent.ROLL_OVER, changeMenu4RollOverHandler);
changeMenuButton[4].addEventListener(MouseEvent.ROLL_OUT, changeMenu4RollOutHandler);
changeMenuButton[4].addEventListener(MouseEvent.CLICK, changeMenu4ClickHandler);
}
private function changeMenu1RollOverHandler(event:MouseEvent):void {
changeMenuRollOver(1);
}
private function changeMenu1RollOutHandler(event:MouseEvent):void {
changeMenuRollOut(1);
}
private function changeMenu1ClickHandler(event:MouseEvent):void {
changeMenuClick(1);
}
private function changeMenu2RollOverHandler(event:MouseEvent):void {
changeMenuRollOver(2);
}
private function changeMenu2RollOutHandler(event:MouseEvent):void {
changeMenuRollOut(2);
}
private function changeMenu2ClickHandler(event:MouseEvent):void {
changeMenuClick(2);
}
private function changeMenu3RollOverHandler(event:MouseEvent):void {
changeMenuRollOver(3);
}
private function changeMenu3RollOutHandler(event:MouseEvent):void {
changeMenuRollOut(3);
}
private function changeMenu3ClickHandler(event:MouseEvent):void {
changeMenuClick(3);
}
private function changeMenu4RollOverHandler(event:MouseEvent):void {
changeMenuRollOver(4);
}
private function changeMenu4RollOutHandler(event:MouseEvent):void {
changeMenuRollOut(4);
}
private function changeMenu4ClickHandler(event:MouseEvent):void {
changeMenuClick(4);
}
private function changeMenuRollOver(newChangeMenuID:uint):void {
if (Sample.currentChangeMenuID != newChangeMenuID) {
AtTween.COLOR(changeMenuBackground[newChangeMenuID], ROLLOVER_COLOR, ROLLOVER_TIME, ROLLOVER_EASE);
}
}
private function changeMenuRollOut(newChangeMenuID:uint):void {
if (Sample.currentChangeMenuID != newChangeMenuID) {
AtTween.COLOR(changeMenuBackground[newChangeMenuID], ROLLOUT_COLOR[0], ROLLOUT_TIME, ROLLOUT_EASE);
}
}
private function changeMenuClick(newChangeMenuID:uint):void {
Sample.currentChangeMenuID = newChangeMenuID;
//Sample.currentChangeMenuIDが 1なら、
changeMenu[1]の子にあるボタンを無効化し、
それ以外の子にあるボタンを有効化する

SmartButton.change(
changeMenu,
Sample.currentChangeMenuID,
CHANGE_MENU_NUM
);
//ボタンの背景色を変更する
setChangeMenuColor(Sample.currentChangeMenuID);
}
private function setChangeMenuColor(newChangeMenuID:uint):void {
for (var i:uint=1; i<=CHANGE_MENU_NUM; i++) {
if (newChangeMenuID != i) {
AtTween.COLOR(changeMenuBackground[i], DEFAULT_COLOR[0], REVERSE_TIME);
}
}
AtTween.COLOR(changeMenuBackground[newChangeMenuID], DISABLE_COLOR,REVERSE_TIME);
}
private function setClearMenu():void {
clearMenu =
MovieClip(NAVIGATOR.getChildByName("clear"));
clearMenuButton =
SimpleButton(clearMenu.getChildByName("_btn"));
clearMenuBackground =
Sprite(clearMenu.getChildByName("bg"));
}
private function setClearEvent():void {
clearMenuButton.addEventListener(MouseEvent.ROLL_OVER, clearMenuRollOverHandler);
clearMenuButton.addEventListener(MouseEvent.ROLL_OUT, clearMenuRollOutHandler);
clearMenuButton.addEventListener(MouseEvent.CLICK, clearMenuClickHandler);
}
private function clearMenuRollOverHandler(event:MouseEvent):void {
AtTween.COLOR(clearMenuBackground, ROLLOVER_COLOR, ROLLOVER_TIME, ROLLOVER_EASE);
}
private function clearMenuRollOutHandler(event:MouseEvent):void {
AtTween.COLOR(clearMenuBackground, ROLLOUT_COLOR[1], ROLLOUT_TIME, ROLLOUT_EASE);
}
private function clearMenuClickHandler(event:MouseEvent):void {
//changeMenuのすべての子にあるボタンを有効化する
SmartButton.clear(changeMenu, CHANGE_MENU_NUM);
//ボタンの背景色をすべて元に戻す
for (var i:uint=1; i<=CHANGE_MENU_NUM; i++) {
AtTween.COLOR(changeMenuBackground[i], DEFAULT_COLOR[0], REVERSE_TIME);
}
}
private function setEnabledMenu():void {
for (var i:uint=1; i<=ENABLED_MENU_NUM; i++) {
enabledMenu[i] =
MovieClip(NAVIGATOR.getChildByName("enabled" + i));
enabledMenuButton[i] =
SimpleButton(enabledMenu[i].getChildByName("_btn"));
enabledMenuBackground[i] =
Sprite(enabledMenu[i].getChildByName("bg"));
}
}
private function setEnabledEvents():void {
enabledMenuButton[1].addEventListener(MouseEvent.ROLL_OVER, enabledMenu1RollOverHandler);
enabledMenuButton[1].addEventListener(MouseEvent.ROLL_OUT, enabledMenu1RollOutHandler);
enabledMenuButton[1].addEventListener(MouseEvent.CLICK, enabledMenu1ClickHandler);
enabledMenuButton[2].addEventListener(MouseEvent.ROLL_OVER, enabledMenu2RollOverHandler);
enabledMenuButton[2].addEventListener(MouseEvent.ROLL_OUT, enabledMenu2RollOutHandler);
enabledMenuButton[2].addEventListener(MouseEvent.CLICK, enabledMenu2ClickHandler);
}
private function enabledMenu1RollOverHandler(event:MouseEvent):void {
if (Sample.currentEnabledMenuID != 1) {
AtTween.COLOR(enabledMenuBackground[1], ROLLOVER_COLOR, ROLLOVER_TIME, ROLLOVER_EASE);
}
}
private function enabledMenu1RollOutHandler(event:MouseEvent):void {
if (Sample.currentEnabledMenuID != 1) {
AtTween.COLOR(enabledMenuBackground[1], ROLLOUT_COLOR[0], ROLLOUT_TIME, ROLLOUT_EASE);
}
}
private function enabledMenu1ClickHandler(event:MouseEvent):void {
Sample.currentEnabledMenuID = 1;
switchEnabled(Sample.currentEnabledMenuID, 2);
}
private function enabledMenu2RollOverHandler(event:MouseEvent):void {
if (Sample.currentEnabledMenuID != 2) {
AtTween.COLOR(enabledMenuBackground[2], ROLLOVER_COLOR, ROLLOVER_TIME, ROLLOVER_EASE);
}
}
private function enabledMenu2RollOutHandler(event:MouseEvent):void {
if (Sample.currentEnabledMenuID != 2) {
AtTween.COLOR(enabledMenuBackground[2], ROLLOUT_COLOR[0], ROLLOUT_TIME, ROLLOUT_EASE);
}
}
private function enabledMenu2ClickHandler(event:MouseEvent):void {
Sample.currentEnabledMenuID = 2;
switchEnabled(Sample.currentEnabledMenuID, 1);
}
private function switchEnabled(currentID:uint, lastID:uint, time:Number=REVERSE_TIME):void {
//enabledMenu[currentID]の子にあるボタンを無効化する
SmartButton.enabled(enabledMenu[currentID], false);
//enabledMenu[currentID]の背景色を非クリック色へ変更する
AtTween.COLOR(enabledMenuBackground[currentID], DISABLE_COLOR, time);
//enabledMenu[lastID]の子にあるボタンを有効化する(元に戻す)
SmartButton.enabled(enabledMenu[lastID], true);
//enabledMenu[lastID]の背景色を元に戻す
AtTween.COLOR(enabledMenuBackground[lastID], DEFAULT_COLOR[0], time);
}
private function centeringLayout():void {
RelativeLayout.setPos(stage, NAVIGATOR, "cm");
}
}
}

Download

SWFObject 2.0以降で SWFForceSizeを使用する方法

SWFObject2x and SWFForceSize

SWFObject2x and SWFForceSize

SWFForceSize*1SWFObject 2.0以降で用いる方法を以前のエントリーに公開していたのですが、より安全な方法が検証できましたので、下記にサンプルと使用方法を再考しました。

Sample Download

下記、HTML側のサンプルコードでは、SWFObjectSWFForceSizeの動作に必要な部分を緑字と赤字で記述しています。

【HTMLファイル側の記述】*2


<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-language" content="ja" />
<meta http-equiv="content-script-type" content="text/javascript" />
<meta http-equiv="content-style-type" content="text/css" />
<meta name="keywords" content="Flash,SWFObject,SWFForceSize" />
<meta name="description" content="SWFObject2.0以降で SWFForceSizeを使用するサンプルです" />
<title>SWFObject2x and SWFForceSize</title>
<link rel="stylesheet" type="text/css" href="common/css/style.css" media="all" />
<script type="text/javascript" src="common/script/swfobject/swfobject2_2.js"></script>
<script type="text/javascript" src="common/script/swfforcesize/swfforcesize.js"></script>
<script type="text/javascript">
// <![CDATA[
var flashvars = {};
var params = {
bgcolor:"#ffffff",
scale:"noscale"
};
var attributes = {
id: "main",
name: "main"
};
swfobject.embedSWF("sample.swf", "main", "100%", "100%", "9.0.0","common/script/expressinstall/expressInstall.swf", flashvars, params, attributes);

swfobject.addLoadEvent(function() {
var so = document.getElementById("main");
if(so) {
var forcesize = new SWFForceSize(so, 800, 600);
forcesize.onLoadDiv();
}
})

// ]]>
</script>

</head>
<body>
<div id="main">
<div id="plane">
<h1>SWFObject2x and SWFForceSize</h1>
<p>SWFObject2.0以降で SWFForceSizeを使用するサンプルです</p>
<blockquote>
<p>ご使用のブラウザ環境では、このページが正しく表示できない可能性があります。<br />
以下の注意点を確認し、必要な設定を行った上で再度表示してください。</p>
<ul>
<li>ブラウザの JavaScript 設定を有効化してください。</li>
<li>最新の <a href="http://www.adobe.com/go/JP-H-GET-FLASH">Adobe<sup>®</sup> Flash<sup>®</sup> Player</a> をインストールしてください。</li>
</ul>
<p><a href="http://www.adobe.com/go/JP-H-GET-FLASH"><img src="common/images/get_adobe_flash_player.png" alt="Adobe Flash Player のダウンロード" width="158" height="39" /></a></p>
</blockquote>
</div>
</div>
</body>
</html>

CSSファイル側の記述】


@charset "utf-8";

html {
margin : 0;
padding : 0;
height : 100%;
overflow : auto;
}
body {
margin : 0;
padding : 0;
width : 100%;
height : 100%;
}
#main {
position : absolute;
top : 0;
left : 0;
width : 100%;
height : 100%;
line-height : 0;
text-align : center;
}

【動作確認環境】


Windows 7
IE/8.0.7600
Firefox/3.6
Safari/4.0.4
Google Chrome/4.0.249.89
Windows XP SP2
IE/8
Firefox/3.5.3
Safari 4.0.3
Mac OS X 10.5.8
Firefox 3.5.2
Safari 4.0.3

Download

*1:Pixelbreakerより配布されている JavaScriptで、ウィンドウ(Flash表示領域)が指定したサイズより小さくなった際にスクロールバーを表示できます

*2:サンプルでは Flash/代替コンテンツを表示するコンテナの idを "main"、最小ウィンドウサイズを 横:800 px × 縦:600 pxとしています

AS3でオブジェクトをステージ上に相対配置する「RelativeLayout」クラス

RelativeLayout

RelativeLayout

ActionScript3.0でオブジェクトをステージ上に相対配置する「RelativeLayout」クラスを作成しました。

ウィンドウ/ステージリサイズ時にクラスを呼び出すことで、オブジェクトを「中央」や「下付き」、「右付き」等に変更できます。オブジェクトの座標やサイズの変更も可能です。

ご使用の際は、ステージの伸縮を「拡大・縮小なし」、ステージの位置を「左上」に設定し、ステージリサイズ時のイベントリスナーを登録する必要があります。

下記のボタンより、サンプルの閲覧およびソースのダウンロードができます。

Sample Download

【使用例】

center_mc(MovieClip)をステージの中央に配置


RelativeLayout.setPos(stage, center_mc);

righttop_mc(MovieClip)をステージの右上に配置


RelativeLayout.setPos(stage, righttop_mc, "rt");

rightbottom_mc(MovieClip)をステージの右下へ、画面端(下)から24ピクセルの間隔を持って配置


RelativeLayout.setPos(stage, rightbottom_mc, "rb", 0, 24);

leftbottom_mc(MovieClip)をステージの左下へ、オブジェクトの横幅・縦幅を24ピクセルに強制指定して配置


RelativeLayout.setPos(stage, leftbottom_mc, "lb", 0, 0, 24, 24);

resize_mc(MovieClip)の横幅をステージの横幅に合わせる


RelativeLayout.resize(resize_mc, stage.stageWidth);

resize_mc(MovieClip)の横幅・縦幅をステージの横幅・縦幅に合わせる


RelativeLayout.resize(resize_mc, stage.stageWidth, stage.stageWidth);

point_mc(MovieClip)を、左から50ピクセル、上から100ピクセルの場所へ配置する


RelativeLayout.point(point_mc, 50, 100);

rect_mc(MovieClip)を、左から50ピクセル、上から100ピクセルの場所へ配置し、サイズを 240*400ピクセルに変更する


RelativeLayout.rect(rect_mc, 50, 100, 240, 400);

【オブジェクト配置場所】


中央 : "center" or "cm"
上  : "top" or "ct"
右  : "right" or "rm"
下  : "bottom" or "cb"
左  : "left" or "lm"
右上 : "righttop" or "rt"
右下 : "rightbottom" or "rb"
左下 : "leftbottom" or "lb"
左上 : "lefttop" or "lt"

【パラメータ説明: setPos()】

stage


ステージへの参照 (stageWidth, stageHeightを取得するため)
[Stage][省略不可]

$scope


配置場所を変更したいオブジェクト
[DisplayObject][省略不可]

position


オブジェクトの配置場所
[String][規定値:"center"][省略可]

marginX


配置場所からの横マージン
[int][規定値:0][省略可]

marginY


配置場所からの縦マージン
[int][規定値:0][省略可]

w


オブジェクトの横幅
[uint][規定値:0][省略可]

h


オブジェクトの縦幅
[uint][規定値:0][省略可]

【パラメータ説明: resize()】

$scope


リサイズするオブジェクト
[DisplayObject][省略不可]

w


リサイズ時の横幅
[uint][規定値:0][省略可]

h


リサイズ時の縦幅
[uint][規定値:0][省略可]

【パラメータ説明: point()】

$scope


座標を変更するオブジェクト
[DisplayObject][省略不可]

posX


オブジェクトの x座標
[int][省略不可]

posY


オブジェクトの y座標
[int][省略不可]

【パラメータ説明: rect()】

$scope


座標・サイズを変更するオブジェクト
[DisplayObject][省略不可]

posX


オブジェクトの x座標
[int][省略不可]

posY


オブジェクトの y座標
[int][省略不可]

w


オブジェクトの横幅
[uint][規定値:0][省略可]

h


オブジェクトの縦幅
[uint][規定値:0][省略可]

ソースコード

import jp.atziluth.gui.RelativeLayout;


package jp.atziluth.gui{
import flash.display.DisplayObject;
import flash.display.Stage;
import flash.geom.Point;
import flash.geom.Rectangle;
public class RelativeLayout extends DisplayObject {
private static var aimX:int;
private static var aimY:int;
private static var _x:int;
private static var _y:int;
private static var _width:uint;
private static var _height:uint;
private static var rectangle:Rectangle;
public static function setPos(
stage:Stage,
$scope:DisplayObject,
position:String="center",
marginX:int=0,
marginY:int=0,
w:uint=0,
h:uint=0
):void {
if ($scope == null) {
return;
}
RelativeLayout.setSize($scope,w,h);
switch (position) {
case "center" :
case "cm" :
RelativeLayout.aimX = Math.floor(stage.stageWidth / 2 - RelativeLayout._width / 2) + marginX;
RelativeLayout.aimY = Math.floor(stage.stageHeight / 2 - RelativeLayout._height / 2) + marginY;
break;
case "top" :
case "ct" :
RelativeLayout.aimX = Math.floor(stage.stageWidth / 2 - RelativeLayout._width / 2) + marginX;
RelativeLayout.aimY = marginY;
break;
case "right" :
case "rm" :
RelativeLayout.aimX = Math.floor(stage.stageWidth - RelativeLayout._width) - marginX;
RelativeLayout.aimY = Math.floor(stage.stageHeight / 2 - RelativeLayout._height / 2) + marginY;
break;
case "bottom" :
case "cb" :
RelativeLayout.aimX = Math.floor(stage.stageWidth / 2 - RelativeLayout._width / 2) + marginX;
RelativeLayout.aimY = Math.floor(stage.stageHeight - RelativeLayout._height) - marginY;
break;
case "left" :
case "lm" :
RelativeLayout.aimX = marginX;
RelativeLayout.aimY = Math.floor(stage.stageHeight / 2 - RelativeLayout._height / 2) + marginY;
break;
case "righttop" :
case "rt" :
RelativeLayout.aimX = Math.floor(stage.stageWidth - RelativeLayout._width) - marginX;
RelativeLayout.aimY = marginY;
break;
case "rightbottom" :
case "rb" :
RelativeLayout.aimX = Math.floor(stage.stageWidth - RelativeLayout._width) - marginX;
RelativeLayout.aimY = Math.floor(stage.stageHeight - RelativeLayout._height) - marginY;
break;
case "leftbottom" :
case "lb" :
RelativeLayout.aimX = marginX;
RelativeLayout.aimY = Math.floor(stage.stageHeight - RelativeLayout._height) - marginY;
break;
case "lefttop" :
case "lt" :
default :
RelativeLayout.aimX = marginX;
RelativeLayout.aimY = marginY;
break;
}
RelativeLayout.point(
$scope,
RelativeLayout.aimX,
RelativeLayout.aimY
);
}
public static function resize(
$scope:DisplayObject,
w:uint=0,
h:uint=0
):void {
if ($scope == null) {
return;
}
RelativeLayout.setSize($scope,w,h);
$scope.width = RelativeLayout._width;
$scope.height = RelativeLayout._height;
}
public static function point(
$scope:DisplayObject,
posX:int,
posY:int
):void {
if ($scope == null) {
return;
}
RelativeLayout.setPoint(posX, posY);
$scope.x = RelativeLayout._x;
$scope.y = RelativeLayout._y;
}
public static function rect(
$scope:DisplayObject,
posX:int,
posY:int,
w:uint=0,
h:uint=0
):void {
if ($scope == null) {
return;
}
RelativeLayout.setPoint(posX, posY);
RelativeLayout.setSize($scope,w,h);
RelativeLayout.rectangle = new Rectangle(
RelativeLayout._x,
RelativeLayout._y,
RelativeLayout._width,
RelativeLayout._height
);
$scope.x = RelativeLayout.rectangle.x;
$scope.y = RelativeLayout.rectangle.y;
$scope.width = RelativeLayout.rectangle.width;
$scope.height = RelativeLayout.rectangle.height;
}
private static function setSize($scope:DisplayObject,w:uint,h:uint):void {
w ? RelativeLayout._width = w:RelativeLayout._width = $scope.width;
h ? RelativeLayout._height = h:RelativeLayout._height = $scope.height;
}
private static function setPoint(posX:int,posY:int):void {
RelativeLayout._x = posX;
RelativeLayout._y = posY;
}
}
}

サンプルソースコード】

Sample.as


package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import jp.atziluth.gui.RelativeLayout;
public class Sample extends Sprite {
private var title:Sprite=new Title();
private var center:Sprite=new Center();
private var top:Sprite=new Top();
private var right:Sprite=new Right();
private var bottom:Sprite=new Bottom();
private var left:Sprite=new Left();
private var righttop:Sprite=new Righttop();
private var rightbottom:Sprite=new Rightbottom();
private var leftbottom:Sprite=new Leftbottom();
private var lefttop:Sprite=new Lefttop();
private const TITLE_HEIGHT:uint = Math.round(title.height);
public function Sample():void {
setStageProperty();
setStageEvents();
addContainer();
layoutSample();//最初に1度レイアウトを実行する必要があります
}
internal function setStageProperty():void {
//ステージの伸縮を「拡大・縮小なし」に設定(必須)
stage.scaleMode = StageScaleMode.NO_SCALE;
//ステージの位置を「左上」に設定(必須)
stage.align = StageAlign.TOP_LEFT;
}
private function setStageEvents():void {
//ステージリサイズ時のイベントリスナー登録
stage.addEventListener(Event.RESIZE,layoutSample);
}
private function addContainer():void {
this.addChildAt(title, this.numChildren);
this.addChildAt(center, this.numChildren);
this.addChildAt(top, this.numChildren);
this.addChildAt(right, this.numChildren);
this.addChildAt(bottom, this.numChildren);
this.addChildAt(left, this.numChildren);
this.addChildAt(righttop, this.numChildren);
this.addChildAt(rightbottom, this.numChildren);
this.addChildAt(leftbottom, this.numChildren);
this.addChildAt(lefttop, this.numChildren);
}
private function layoutSample(event:Event=null):void {
//「左下」へオブジェクトの縦幅を強制指定して配置
RelativeLayout.setPos(stage, title, "lb", 0, 0, 0, TITLE_HEIGHT);
//title.bg の横幅をステージ幅に合わせる
RelativeLayout.resize(title.getChildByName("bg"), stage.stageWidth);
//「中央」へ下からのマージンを指定して配置
RelativeLayout.setPos(stage, center, "center", 0, -1*Math.round(TITLE_HEIGHT/2));
//「上」に配置
RelativeLayout.setPos(stage, top, "top");
//「右」へ下からのマージンを指定して配置
RelativeLayout.setPos(stage, right, "right", 0, -1*Math.round(TITLE_HEIGHT/2));
//「下」へ下からのマージンを指定して配置
RelativeLayout.setPos(stage, bottom, "bottom", 0, TITLE_HEIGHT);
//「左」に配置
RelativeLayout.setPos(stage, left, "left", 0, -1*Math.round(TITLE_HEIGHT/2));
//「右上」に配置
RelativeLayout.setPos(stage, righttop, "rt");
//「右下」へ下からのマージンを指定して配置
RelativeLayout.setPos(stage, rightbottom, "rb", 0, TITLE_HEIGHT);
//「左下」へ下からのマージンを指定して配置
RelativeLayout.setPos(stage, leftbottom, "lb", 0, TITLE_HEIGHT);
//「左上」に配置
RelativeLayout.setPos(stage, lefttop, "lt");
}
}
}

【更新履歴】

2010/01/14

座標を変更するクラスメンバー、pointを追加しました
座標とサイズを変更するクラスメンバー、rectを追加しました

Download

AS3で不要になったインスタンスを削除しメモリを解放する「Cleaner」クラス

ActionScript3.0で不要になったインスタンスを削除しメモリを解放する「Cleaner」クラスを作成しました。

指定したオブジェクトの子を、任意の数まで削除します。新しい子から順番に削除するか、古い子から順番に削除するかの指定と、最後にオブジェクトへ nullを代入してメモリを解放するかの指定ができます。

サンプルでは、オブジェクトへ子を追加した後と削除した後に、それぞれのオブジェクトが持つ子の数を出力しています。

下記のボタンより、サンプルおよびソースのダウンロードができます。

Download

【使用例】

_container(DisplayObjectContainer)の子を、古いものから順番に全て削除する


Cleaner.deleteContainer(_container);

_mc(MovieClip)の子を、古いものから順番に全て削除し、最後に nullを代入する


Cleaner.deleteMovieClip(_mc, 0, null);

_sp(Sprite)の子を、最後の1つを除いて新しいものから順番に削除する


Cleaner.deleteSprite(_sp, 1, "null,undefined以外の文字列", true);

【パラメータ説明】

_container, _mc, _sp


子を削除するオブジェクト
[DisplayObjectContainer, MovieClip, Sprite][省略不可]

remainNum


幾つ子を残すか
[uint][規定値:0][省略可]

toNull


最後にオブジェクトに nullを代入する場合は、nullか undefinedを指定
[String][規定値:"String as Null"((パラメータ:toNullの初期値は、nullと undefined以外の文字列にしています。undefinedも nullに変換されてしまうんですね(TT)。is演算子を使うなどもっと良い判別方法があるかもしれません。))][省略可]

isReverse


新しいもの/上から順番に削除するか
[Boolean][規定値:false][省略可]

ソースコード

import jp.atziluth.utils.Cleaner;


package jp.atziluth.utils{
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.display.Sprite;
public class Cleaner {
public static function deleteContainer(
_container:DisplayObjectContainer,
remainNum:uint=0,
toNull:String="String as Null",
isReverse:Boolean=false
):void {
if (_container == null) {
return;
}
if (isReverse) {
while (_container.numChildren > remainNum) {
_container.removeChildAt(_container.numChildren - 1);
}
} else {
while (_container.numChildren > remainNum) {
_container.removeChildAt(0);
}
}
if (toNull == null) {
_container = null;
}
}
public static function deleteMovieClip(
_mc:MovieClip,
remainNum:uint=0,
toNull:String="String as Null",
isReverse:Boolean=false
):void {
if (_mc == null) {
return;
}
if (isReverse) {
while (_mc.numChildren > remainNum) {
_mc.removeChildAt(_mc.numChildren - 1);
}
} else {
while (_mc.numChildren > remainNum) {
_mc.removeChildAt(0);
}
}
if (toNull == null) {
_mc = null;
}
}
public static function deleteSprite(
_sp:Sprite,
remainNum:uint=0,
toNull:String="String as Null",
isReverse:Boolean=false
):void {
if (_sp == null) {
return;
}
if (isReverse) {
while (_sp.numChildren > remainNum) {
_sp.removeChildAt(_sp.numChildren - 1);
}
} else {
while (_sp.numChildren > remainNum) {
_sp.removeChildAt(0);
}
}
if (toNull == null) {
_sp = null;
}
}
}
}

サンプルソースコード】

Sample.as


package {
import flash.display.MovieClip;
import flash.display.Sprite;
import jp.atziluth.utils.Cleaner;
public class Sample extends Sprite {
private var _container:Container=new Container();
private var _mc:MovieClip=new MovieClip();
private var _sp:Sprite=new Sprite();
private var children:Array=new Array();
public function Sample():void {
addScopes();
addChildren();//削除するターゲットの追加
tracer("Phase1");//ターゲット追加後の numChildren出力

deleteScopes();//追加したターゲットの削除
tracer("Phase2");//ターゲット削除後の numChildren出力
}
private function addScopes():void {
this.addChild(_container);
this.addChild(_mc);
this.addChild(_sp);
}
private function addChildren():void {
children[0]=new Array();
children[1]=new Array();
children[2]=new Array();
iterate(_container, children[0], 3);
iterate(_mc, children[1], 5);
iterate(_sp, children[2], 7);
}
private function iterate($scope:Object, $children:Array, iterateNum:uint=1):void {
for (var i:uint; i<iterateNum; i++) {
$children[i]=new Sprite();
$scope.addChild($children[i]);
}
}
private function deleteScopes():void {
Cleaner.deleteContainer(_container, 0, null);
Cleaner.deleteMovieClip(_mc, 0, null);
Cleaner.deleteSprite(_sp, 0, null);
}
private function tracer(str:String=null):void {
trace(str+"-------------------------------------");
trace("_container.numChildren: "+_container.numChildren);
trace("_mc.numChildren: "+_mc.numChildren);
trace("_sp.numChildren: "+_sp.numChildren);
trace("-------------------------------------------");
}
}
}

【サンプル出力結果】


Phase1-------------------------------------
_container.numChildren: 3
_mc.numChildren: 5
_sp.numChildren: 7

                                                                                    • -

Phase2-------------------------------------
_container.numChildren: 0
_mc.numChildren: 0
_sp.numChildren: 0

                                                                                    • -

Download

AS3で外部SWFの読み込みとロード状況の監視をする「SWFLoader」クラス

SWFLoader

SWFLoader

ActionScript3.0で外部SWFの読み込みとロード状況の監視をする「SWFLoader」クラスを作成しました。

SWFファイルを読み込むターゲットと、SWFファイルへのパスを指定して使用します。

ロード開始時と完了時に実行する関数を追加指定したり、ローディング時とロード完了時のフラグを外部から取得することが可能です。

下記のボタンより、ソースのダウンロード及びサンプルの閲覧ができます。

Sample Download

【使用例】

main.swfを読み込み


var myLoader:SWFLoader=new SWFLoader();
myLoader.load(this,"main.swf");

main.swfを _mc(MovieClip)へ読み込み


var myLoader:SWFLoader=new SWFLoader();
myLoader.load(_mc,"main.swf");

main.swfを _mc(MovieClip)へ読み込み、ロード開始時に onLoadFunctionを実行する


var onLoadFunction:Function = function(){
trace("外部SWFのロードが開始されました")
};
var myLoader:SWFLoader=new SWFLoader();
myLoader.load(_mc,"main.swf", onLoadFunction);

main.swfを _mc(MovieClip)へ読み込み、ロード完了時に onCompleteFunctionを実行する


var onCompleteFunction:Function = function(){
trace("外部SWFのロードが完了しました")
};
var myLoader:SWFLoader=new SWFLoader();
myLoader.load(_mc,"main.swf", null, onCompleteFunction);

【ロード状況の取得】

ローディング中であればメッセージを出力する


if(SWFLoader.loading) trace("外部SWFのロード中です…(TT)b");

ロードが完了していればメッセージを出力する


if(SWFLoader.complete) trace("外部SWFのロードが完了しました\(^o^)/");

【パラメータ説明】

_container


外部SWFをロードするターゲット
[DisplayObjectContainer][省略不可]

url


ロードする外部SWFへのパス
[String][省略不可]

onLoadFunction


ロード開始時に実行される関数
[Function][規定値:null][省略可]

onCompleteFunction


ロード完了時に実行される関数
[Function][規定値:null][省略可]

ソースコード

import jp.atziluth.system.SWFLoader;


package jp.atziluth.system{
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import caurina.transitions.Tweener;
import jp.atziluth.utils.cleaner;
public class SWFLoader extends MovieClip {
private var _container:DisplayObjectContainer;
private var loader:Loader;
private static var onLoadFunction:Function;
private static var onCompleteFunction:Function;
public static var loadProgress:loadClip=new loadClip();
private static var isLoading:Boolean = false;
private var totalBytes:Number;
private var loadedBytes:Number;
private var barscale:Number;
private var per:uint;
private var Tween:Function = Tweener.addTween;
private var removeTween:Function = Tweener.removeTweens;
public function load(
_container:DisplayObjectContainer,
url:String,
onLoadFunction:Function=null,
onCompleteFunction:Function=null
):void {
var swfURL:URLRequest = new URLRequest(url);
var loader:Loader = new Loader();
this.loader = loader;
this._container = _container;
this._container.addChildAt(loader, this._container.numChildren);
SWFLoader.onLoadFunction = onLoadFunction;
SWFLoader.onCompleteFunction = onCompleteFunction;
loader.contentLoaderInfo.addEventListener(Event.OPEN, onLoadHandler);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorHandler);
loader.visible = false;
loader.load(swfURL);
}
private function onLoadHandler(event:Event):void {
_container.addChildAt(SWFLoader.loadProgress,_container.numChildren);
with (SWFLoader.loadProgress) {
name = "preloader";
alpha = 0;
}
if (SWFLoader.loadProgress.alpha < 1) {
Tween(
SWFLoader.loadProgress,{
alpha:1,
time:.25,
transition:"Strong.easeOut"
});
}
if (SWFLoader.onLoadFunction != null) {
SWFLoader.onLoadFunction();
}
SWFLoader.isLoading = true;
}
private function onProgressHandler(event:ProgressEvent):void {
totalBytes = event.bytesTotal;
loadedBytes = event.bytesLoaded;
per = Math.floor(loadedBytes / totalBytes * 100);
barscale = loadedBytes / totalBytes;
SWFLoader.loadProgress.bar.scaleX = barscale;
SWFLoader.loadProgress.per.text = per.toString() + "%";
}
private function onCompleteHandler(event:Event):void {
Tween(
SWFLoader.loadProgress,{
alpha:0,
time:2,
transition:"easeInOutCubic",
onComplete:finishLoader
});
function finishLoader():void {
removeTween(SWFLoader.loadProgress);
cleaner.deleteContainer(SWFLoader.loadProgress,0,null);
loader.contentLoaderInfo.removeEventListener(Event.OPEN, onLoadHandler);
loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgressHandler);
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onCompleteHandler);
loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onIOErrorHandler);
loader.visible = true;
}
if (SWFLoader.onCompleteFunction != null) {
SWFLoader.onCompleteFunction();
}
SWFLoader.isLoading = false;
}
private function onIOErrorHandler(event:Event):void {}
public static function get loading():Boolean {
return (SWFLoader.isLoading);
}
public static function get complete():Boolean {
return !(SWFLoader.isLoading);
}
}
}

サンプルソースコード: "preloader.swf"】

Preloader.as


package {
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import jp.atziluth.system.SWFLoader;
public class Preloader extends SWFLoader {
private var mainLoader:SWFLoader=new SWFLoader();
private var onLoadFunction:Function = function(){
Preloader.loadProgressLayout()
};
private var onCompleteFunction:Function = function(){};
public function Preloader():void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.frameRate = 60;
mainLoader.load(
this,
"main.swf",
onLoadFunction,
onCompleteFunction
);
stage.addEventListener(Event.RESIZE,onStageResize);
}
private function onStageResize(event:Event=null):void {
Preloader.loadProgressLayout();
}
private static const ICON_SIZE:uint = 20;
public static function loadProgressLayout():void {
with (SWFLoader.loadProgress) {
alpha = 1;
x = 0;
y = 0;
per.visible = false;
per.alpha = 0;
bar.y = Math.round(stage.stageHeight / 2 - bar.height / 2);
bar.cont.width = stage.stageWidth;
basebar.y = bar.y;
basebar.cont.width = bar.cont.width;
icon.x = Math.round(stage.stageWidth / 2 - Preloader.ICON_SIZE / 2);
icon.y = Math.round(bar.y + (Preloader.ICON_SIZE+3));
}
}
}
}

サンプルソースコード: "main.swf"】

Main.as


package {
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import jp.atziluth.gui.relativeLayout;
public class Main extends MovieClip {
private const COMPLETE:completeClip=new completeClip();
public function Main():void {
super();
this.addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(event:Event):void {
this.removeEventListener(Event.ADDED_TO_STAGE, init);
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
this.addChild(COMPLETE);
stage.addEventListener(Event.RESIZE,onStageResize);
lauoutMain();
}
private function onStageResize(event:Event=null):void {
lauoutMain();
}
private function lauoutMain():void {
relativeLayout.init(stage, COMPLETE);
}
}
}

【留意事項】

ロード状況を知らせるプログレスバーにはライブラリのリンケージクラス: "loadClip"を使用しています。

少し面倒ですがライブラリにある "_loadClip"フォルダを丸ごとコピーするか、SWFLoader.asの "loadProgress"、"loadClip"と記載のある箇所を編集してご使用ください。

改良案のご提示などお待ちしています。こちらのコメント欄か、info[at]atziluth.jp までお知らせいただけると嬉しいです。

【更新履歴】

2010/04/02

改訂版(Version 1.1)を公開しました

Download

AS3でドット模様のビットマップテクスチャを全画面に描画する「BitmapTexture」クラス

BitmapTexture

BitmapTexture

ActionScript3.0でドット模様のビットマップテクスチャを全画面に描画する「BitmapTexture」クラスを作成しました。

背景全画面に読み込んだ画像の上へ重ねてみたところ、目の錯覚で画質が若干改善したように感じます。

デフォルトではユーザーの解像度を取得し全画面に描画しますが、ステージサイズや任意のサイズを指定することも可能です。

下記のボタンより、ソースのダウンロード及びサンプルの閲覧ができます。

Sample Download

【使用例】

TEXTURE(DisplayObjectContainer)にライブラリのリンケージクラス '_BitmapTexture'を読み込み全画面に描画


BitmapTexture.load(TEXTURE);

TEXTURE(DisplayObjectContainer)にドットテクスチャを全画面に描画


BitmapTexture.draw(TEXTURE);

TEXTURE(DisplayObjectContainer)の縦480ピクセル×横240ピクセルの範囲へドットテクスチャを描画


BitmapTexture.draw(TEXTURE, 480, 240);

【パラメータ説明】

$scope


テクスチャを描画するオブジェクト
[DisplayObjectContainer][省略不可]

w


テクスチャを描画する横範囲
[規定値:0 -> 代入値:Capabilities.screenResolutionX][省略可]

h


テクスチャを描画する縦範囲
[規定値:0 -> 代入値:Capabilities.screenResolutionY][省略可]

p1


BitmapDataの第1・第2引数へ代入される値(調整用)
[規定値:2][省略可]

p2


BitmapData.setPixel32の第1・第2引数へ代入される値(調整用)
[規定値:0][省略可]

p3


BitmapData.setPixel32の第1・第2引数へ代入される値(調整用)
[規定値:1][省略可]

ソースコード

import jp.atziluth.gui.BitmapTexture;


package jp.atziluth.gui{
import flash.display.DisplayObjectContainer;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.system.Capabilities;
import jp.atziluth.utils.cleaner;
public class BitmapTexture extends Sprite {
private static var scope:DisplayObjectContainer;
private static var w:uint;
private static var h:uint;
private static var bmd:BitmapData;
private static var sp:Sprite;
public static function draw($scope:DisplayObjectContainer, w:uint=0, h:uint=0, p1:uint=2, p2:uint=0, p3:uint=1):void {
if ($scope == null) {
return;
}
BitmapTexture.initialize($scope, w, h);
var bmd:BitmapData = new BitmapData(p1,p1,true,0x00FFFFFF);
bmd.setPixel32(p2, p2, 0xFF000000);
bmd.setPixel32(p3, p3, 0xFF000000);
BitmapTexture.bmd = bmd;
BitmapTexture.beginFill();
BitmapTexture.addStage();
}
public static function load($scope:DisplayObjectContainer, w:uint=0, h:uint=0):void {
if ($scope == null) {
return;
}
BitmapTexture.initialize($scope, w, h);
var bmd:BitmapData = new _BitmapTexture(0,0);
BitmapTexture.bmd = bmd;
BitmapTexture.beginFill();
BitmapTexture.addStage();
}
private static function initialize($scope:DisplayObjectContainer, w:uint, h:uint):void {
BitmapTexture.scope = $scope;
w ? BitmapTexture.w = w:BitmapTexture.w = Capabilities.screenResolutionX;
h ? BitmapTexture.h = h:BitmapTexture.h = Capabilities.screenResolutionY;
}
private static function beginFill():void {
var sp:Sprite = new Sprite();
sp.graphics.beginBitmapFill(BitmapTexture.bmd, null, true, true);
sp.graphics.drawRect(0, 0, BitmapTexture.w, BitmapTexture.h);
sp.graphics.endFill();
BitmapTexture.sp = sp;
}
private static function addStage():void {
if (BitmapTexture.scope.numChildren) {
cleaner.deleteContainer(BitmapTexture.scope, 0, null);
}
BitmapTexture.scope.addChildAt(BitmapTexture.sp, 0);
}
}
}

サンプルソースコード】

Sample.as


package {
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import jp.atziluth.gui.BitmapTexture;
public class Sample extends MovieClip {
private const TEXTURE:_container=new _container();
private const MODE_LOAD:String = "1";
private const MODE_DRAW:String = "2";
private var BitmapTextureMode:String = MODE_LOAD;
public function Sample():void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
this.addChildAt(TEXTURE, 0);
switch (BitmapTextureMode) {
case MODE_LOAD :
//リンケージクラス: _BitmapTexture (PNGファイル) の読み込み
BitmapTexture.load(TEXTURE);
break;
case MODE_DRAW :
//1px間隔でドットテクスチャを描画
BitmapTexture.draw(TEXTURE);
break;
}
}
}
}

Download