Linux Install

Android

Linux Tools

Linux AV

Linux Memo

WINDOWS

PROGRAM

動画 Memo

音楽 Memo

モバイルアプリ Memo

FILE FORMAT

PROTOCOL

DEVICE

BookMark

その他


AS3   

CodeRest

時計

#htmlinsert(flash,swf=clock.swf,bgcolor=#FFFFFF,name=flashAbout_small,width=300,height=50);

var tf:TextField = new TextField();
addChild(tf);
var timer:Timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER,updateTime);
timer.start();
function updateTime(e:Event){
	var currentTime:Date = new Date();
	tf.text = zeroNum(currentTime.hours)+":"+zeroNum(currentTime.minutes)+":"+zeroNum(currentTime.seconds);
}
function zeroNum(num:int):String{
	return (num<10)?"0"+num:""+num;
}

便利

sprintf のようなもの

http://svn.coderepos.org/share/lang/actionscript/sprintf/sprintf.as

var_dump のようなもの

http://www.flexer.info/2008/06/25/dump-debug-method-like-var_dump-function-in-php-and-debug-class/
import com.flexer.Debug;
trace(Debug.dump(hogehoge));

traceの出力を FireFox で

https://addons.mozilla.org/ja/firefox/addon/3469

正規表現

var result:Array = str.match(/(hoge)/);
trace(result[1]);
str = str.replace(/mein/g,"main");

配列(結合配列、連想配列)

初期化

var array1:Array = ["a","b","c"];
var hash:Object = {key1:"value1",key2:"value2"};

配列総なめ(カウントがいる場合)

for (var i:int=0; i< array.length; ++i){
  trace(i + ":" + array[i]);
}

連想配列(結合配列)の値のみ

for each(var value:Object in array){
  trace(value);
}

結合配列のキーと値

for (var key:String in array){
   var value:Object = array[key];
   trace(key + ":" + value);
}

Drag&Drop

大本

object.addEventListener(MouseEvent.MOUSE_DOWN, onDrag);

ドラッグイベント

private function onDrag(e:MouseEvent):void{
    switch(e.type){
      case MouseEvent.MOUSE_DOWN:
        e.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN,onDrag);
        e.currentTarget.stage.addEventListener(MouseEvent.MOUSE_UP,onDrag);
        e.currentTarget.startDrag(【必要に応じて動く範囲を規定】);
        break;
      case MouseEvent.MOUSE_UP:
        e.currentTarget.addEventListener(MouseEvent.MOUSE_DOWN,onDrag);
        e.currentTarget.stage.removeEventListener(MouseEvent.MOUSE_UP,onDrag);
        e.currentTarget.stopDrag();
        break;
     }
} 

HTMLからの引数

  • URLで直接の場合
    http://hogehoge/hoge.swf?value=3
  • .html
    <script language="JavaScript" type="text/javascript">
    	AC_FL_RunContent(
    		'width', '100%',
    		'height', '100%',
                        :
    		'FlashVars', 'value=3', <=これを追加
    		'salign', ''
    		); //end AC code
    </script>
  • .fla
    var flashVars:Object = loaderInfo.parameters;
    trace(flashVars["value"]);

資料

adobe

  • 大まかに、fl. / flash. / mx. の3つのパッケージがあり、fl は flash のみ mx は flex のみ flash は双方で共通に使える
  • コンパチな as3 を作るなら flash のみを使えばよい
  • 依存するものを作った場合には swc レベルまでコンパイルする必要がある
  • ActionScript3 APIリファレンス
    http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/index.html?class-summary.html&all-classes.html
  • Flex3 APIリファレンス
    http://livedocs.adobe.com/flex/3_jp/langref/

SWF / FLA 仕様


  • BlendMode
    http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/flash/display/BlendMode.html
  • Bitmap
    http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/flash/display/Bitmap.html
  • BitmapData
    http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/flash/display/BitmapData.html
  • FileReference
    http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/flash/net/FileReference.html
  • ビットマップ操作の基礎
    http://livedocs.adobe.com/flash/9.0_jp/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000242.html

右クリック

  • Javascriptで強引に
    http://www.kirupa.com/forum/showthread.php?t=270568

お絵かきツール

  • ActionScript 3 版お絵かきソフト(ペイント)
    http://onegame.bona.jp/paint/5/
  • FC2
    http://fc2blogmanual.blog60.fc2.com/blog-entry-108.html
  • FlashCS3でお絵かきツール
    http://www.func09.com/wordpress/archives/149
  • バケツツールつき
    http://nondelion.com/archives/2008/02/01/1740
  • eraser
    http://kozy.heteml.jp/pukiwiki/index.php?ActionScript3.0%20%A4%AA%B3%A8%A4%AB%A4%AD%A5%C4%A1%BC%A5%EB
  • codezineの
    http://codezine.jp/article/detail/298?p=2
  • papi-bo
    http://www.papiness.com/papi-blo/2008/07/oekaki.html

PNGを扱う

  • as3corelib を使用。
    http://code.google.com/p/as3corelib/
    http://cs3book.flashoop.jp/wiki/index.php?PNG%E3%82%A8%E3%83%B3%E3%82%B3%E3%83%BC%E3%83%80
  • PNGEncoder
    http://www.kaourantin.net/2005/10/png-encoder-in-as3.html

画像upload/download

  • upload
    http://www.ficc.jp/labs/archives/ando/flash_img_file/
  • FileReference.download() -adobe公式
    http://livedocs.adobe.com/flex/2_jp/langref/flash/net/FileReference.html#download

Flash10のセキュリティ関連

  • download
    http://level0.kayac.com/2008/10/fp10_filereference_081028.php
  • uplaod
    http://blogs.yahoo.co.jp/miyaoshu/3106756.html
  • flash10では直接ファイルを保存できるんだって
    http://www.papiness.com/papi-blo/2008/11/flash-player-10-securityerror.html

開発環境関連

  • ローカルswfからネットワーク接続テスト
    http://kb.adobe.com/selfservice/viewContent.do?externalId=4c093f20&sliceId=1
  • デバッグ支援
    http://d.hatena.ne.jp/nitoyon/20081016/as3_debug_library
  • ThunderBolt AirConsole
    http://level0.kayac.com/2008/11/3_thunderbolt_airconsole_1.php
  • Flash Decompiler Trillix
    http://www.webnomoto.com/software/eshop/Order.aspx?ProductID=7
  • Sothink SWF Decompiler(あんまし・・)
    http://www.sothink.com/product/flashdecompiler/download.htm
  • Sothlink Motion Decompiler 3 (割とよいかも?)
  • MTASC

その他

  • バイトコード
    http://cs3book.flashoop.jp/wiki/index.php?%E3%83%90%E3%82%A4%E3%83%88%E3%82%B3%E3%83%BC%E3%83%89%E3%81%8C%E6%89%B1%E3%81%88%E3%82%8B%E3%83%A1%E3%83%AA%E3%83%83%E3%83%88%E3%81%AE%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB
  • as2 -> as3
    http://cs3book.flashoop.jp/wiki/index.php?AS2%E3%81%8B%E3%82%89AS3%E3%81%B8%E3%81%AE%E7%A7%BB%E8%A1%8C
  • 3次ベジェ
    http://www.ficc.jp/labs/archives/akira/3d_beizer/
  • asで言語? Fink
    http://level0.kayac.com/adobe_air/
  • tweener?

DispatchEvent

DispatchEventの使いどころ

子のアニメーションが終わったことを親に知らせる例

使わないやりかた

Parent.as

import flash.display.Sprite;
public class Parent extends Sprite{
	public function Parent():void{
		addEventListener("addedToStage",onAdd);
	}
	private function onAdd(e):void{
		removeEventListener("addedToStage",onAdd);
		var c:Child = new Child();
		c.p = this;
		stage.addChild(c);
	}
	public function end():void{
		trace("右端です");
	}
}

Child.as

import flash.text.TextField;
public class Child extends TextField{
	public var p;
	public function Child():void{
		this.text = "child";
		addEventListener("enterFrame",onEnter);
	}
	public function onEnter(e){
		x++ ;
		if (stage && (x > stage.stageWidth)) {
			removeEventListener("enterFrame",onEnter);
			p.end(); // ← 親のインスタンスを知っていないといけない
		}
	}
}

使ってみた例

Parent.as

import flash.display.Sprite;
public class Parent extends Sprite{
	public function Parent():void{
		addEventListener("addedToStage",onAdd);
	}
	private function onAdd(e):void{
		removeEventListener("addedToStage",onAdd);
		var c:Child = new Child();
		c.addEventListener("complete",end); // ←リスナーを登録
		stage.addChild(c);
	}
	public function end(e):void{
		removeEventListener("complete",end);
		trace("右端です");
	}
}

Child.as

import flash.text.TextField;
import flash.events.Event;
public class Child extends TextField{
	public function Child():void{
		this.text = "child";
		addEventListener("enterFrame",onEnter);
	}
	public function onEnter(e){
		x++ ;
		if (stage && (x > stage.stageWidth)) {
			removeEventListener("enterFrame",onEnter);
			dispatchEvent(new Event(Event.COMPLETE)); // ←親を知らなくて良い
		}
	}
}

※ Child.as から親への参照がなくなり、独立性が高まる。

BASIC認証

下記モジュールを入れる

  • as3corelib.swc
  • as3crypto.swc
  • as3httpclientlib*.swc
private function main():void{
  var client:HttpClient = new HttpClient();
  var uri:URI = new URI("http://hogehoge.com/secret/");
  var request:HttpRequest = new Get();
  var _user:String = "test";
  var _password:String = "test";
  request.addHeader("Authorization","Basic "+Base64.encode(_user+":"+_password));
  client.listener.onData = this.dataHandler;
  client.request(uri,request);
}
private function dataHandler(e:HttpDataEvent):void{
  var str:String = e.readUTFBytes();
  trace(str);
}

Flash Player バージョン比率

http://www.adobe.com/products/flashplatformruntimes/statistics.html