Flashの知らなかった事実メモ

いまFusekitのソースを読んでるところだけど、色々知らないことがわかってきたのでとりあえずメモ。


1. functionの引数はすべてarguments変数に格納されている。
例えば

function countArgs(args : String) : Void {
trace(arguments[1]);
for(var str : String in arguments){
trace(arguments[str]);
}
}
countArgs("sss","ccc","ddd")

//output
ccc
ddd
ccc
sss

まったく持って知らんかった、若干ショック。
引数の定義ってすごいあいまいなのね。


2. newを動的に行う方法

var _array = new ("Array")("111","222");
trace(_array[1]);

//output
222

これでクラスを動的に組み込める。ヤッホー(AA略
[追記]
newするクラスはObjectを継承していないと動作しない。
なんでだろ?
[追記の追記]
どうもそのnewする前にあらかじめどこかでインスタンスを作っていないと動作しないみたい。
ヌカ喜びだった...

bind9の設定

会社のサーバをリプレイス中。
まずは第一弾でbind9のインストール。

まずは/usr/local/etc/pkgtools.confにオプションを書いてインストール

vi /usr/local/etc/pkgtools.conf

    • -

MAKE_ARGS = {
'dns/bind9' => 'WITH_PORT_REPLACES_BASE_BIND9=yes',
}

    • -

portinstall dns/bind9


次に/etc/rc.confにOS起動時に立ち上がるように記述

vi /etc/rc.conf

    • -

named_enable="YES"
named_program="/usr/sbin/named"
named_flags="-4 -u bind"
named_pidfile="/var/run/named/pid"
named_chrootdir="/var/named"
named_chroot_autoupdate="YES"
named_symlink_enable="YES"

    • -


/var/named/etc/namedbに移動して設定ファイルをいじる準備をする

cd /var/named/etc/namedb
sh make-localhost
vi chg_cache.sh

    • -

#!/bin/sh
#generated by pmobiuse

/usr/bin/dig @a.root-servers.net . ns >/etc/namedb/named.root.new 2>&1

case `cat /etc/namedb/named.root.new` in
echo "The root.hints file update has FAILED."
echo "This is the dig output reported:"
echo
cat /etc/namedb/named.root.new
exit 0
;;
esac

echo "The root.hints file has been updated to contain the following infomation:"
cat /etc/namedb/named.root.new

chown root.wheel /etc/namedb/named.root.new
chmod 444 /etc/namedb/named.root.new
rm -f /etc/namedb/named.root.old
mv -f /etc/namedb/named.root /etc/namedb/named.root.old
mv -f /etc/namedb/named.root.new /etc/namedb/named.root
kill -HUP `/bin/cat /var/run/named.pid`
echo "The nameserver has been restarted to ensure that the update is complete."
echo "The previous root.hints file is now called /etc/namedb/named.root.old"
exit 0

    • -

rndc-confgen -a -b 512 -r /dev/urandom -u bind
chown bind:bind rndc.key && chmod 0400 rndc.key
cp rndc.conf.sample rndc.conf
chmod 600 rndc.conf
vi rndc.conf

    • -

options {
default-server localhost;
default-key "rndc-key";
};

server localhost {
key "rndc-key";
};

#key "key" {
# algorithm hmac-md5;
# secret "c3Ryb25nIGVub3VnaCBmb3IgYSBtYW4gYnV0IG1hZGUgZm9yIGEgd29tYW4K";
#};
include "/etc/namedb/rndc.key";

    • -

chg_cache.shはIPv6のために bind9 を覚えるページ(fkimura.com)からいただきました。
rootサーバが変更時の対応に使う。
rndcはbindを再起動せずに設定を反映するために使うらしいけど、いつも再起動してるからあまり使ったことがない。


いよいよ
bindの設定ファイルいじります。
とりあえず内部向けに動いていればいいのでnamed.confはこんな感じ

vi named.conf

    • -

include "/etc/namedb/rndc.key";

controls {
inet 127.0.0.1 allow { localhost; } keys { "rndc-key"; };
};

options {
directory "/etc/namedb";
pid-file "/var/run/named/pid";
dump-file "/var/dump/named_dump.db";
statistics-file "/var/stats/named.stats";

version "";
listen-on-v6 { none; };
auth-nxdomain yes;

allow-transfer { none; };
//slave server none;
};

logging {
channel bind_log {
file "/var/log/named.log" versions 3 size 2m;
severity dynamic;
print-time yes;
print-category yes;
};
category xfer-out {
bind_log;
};
category default {
default_syslog;
};
};

//zone "." {
// type hint;
// file "named.root";
//};

//zone "0.0.127.IN-ADDR.ARPA" {
// type master;
// file "master/localhost.rev";
//};

// RFC 3152
//zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.ARPA" {
// type master;
// file "master/localhost-v6.rev";
//};

acl "intra" {
172.29.0.0/16;
127.0.0.1;
};

view "internal" {
match-clients { intra; };
recursion yes;

zone "." {
type hint;
file "named.root";
};

zone "localhost" {
type master;
file "master/localhost.rev";
};

zone "0.0.127.in-addr.arpa" {
type master;
file "master/0.0.127.in-addr.arpa";
};

zone "example.jp" {
type master;
file "master/example.jp.zone";
};

zone "29.172.in-addr.arpa" {
type master;
file "master/29.172.in-addr.arpa";
};
};

    • -


最後にゾーンファイルを作成して終わり

cd master
cp localhost.rev 0.0.127.in-addr.arpa
vi 0.0.127.in-addr.arpa

    • -

$TTL 3600

@ IN SOA gw.example.jp. root.gw.example.jp. (
20060501 ; Serial
3600 ; Refresh
900 ; Retry
3600000 ; Expire
3600 ) ; Minimum
IN NS gw.example.jp.
1 IN PTR localhost.

    • -

vi 29.172.in-addr.arpa

    • -

$TTL 3600

@ IN SOA gw.example.jp. root.gw.example.jp. (
20060501 ; Serial
3600 ; Refresh
900 ; Retry
3600000 ; Expire
3600 ) ; Minimum
IN NS gw.example.jp.
1 IN PTR localhost.

    • -

vi example.jp.zone

    • -

$TTL 3600
vi example.jp.zone
@ IN SOA gw.example.jp. root.gw.example.jp. (
20060428 ; Serial
3600 ; Refresh
900 ; Retry
3600000 ; Expire
3600 ) ; Minimum
IN NS gw.example.jp.
IN MX 10 gw.example.jp.
IN A 172.29.0.1
gw IN A 172.29.0.1

    • -

以上(また長いエントリになった...)。

カーネルファイルが読込、追記、削除ができるようになってます

Mimori's Algorithms tDiaryから

そういうことらしい。
必要な分を必要なだけ書き込めばよくなったことでだいぶ見通しがよくなった。
とりあえず自分が必要なのはALTQとIPSec追記ぐらいかな。
バイス削るのもだるいしな。

include GENERIC
ident OJOS
options ALTQ
options ALTQ_CBQ
options ALTQ_RED
options ALTQ_RIO
options ALTQ_HFSC
options ALTQ_CDNR
options ALTQ_PRIQ

options IPSEC
options IPSEC_ESP

Winkで説明書作成

Winkとはディスクトップをキャプチャしてswfを吐き出してくれるアプリケーション。windows版とlinux版がある。


あるサイトの管理をほかの会社に移管することになり私がしていたユーザ登録とそれに伴うシステムの設定を先方に伝えるための資料が欲しいと言われ、当初は画面のキャプチャとそれに説明を書き加えたPDFを渡そうと思っていたのだが、使い慣れない堅苦しい文章を書くのが面倒くさくなり、画面操作なんだから文書より画面操作そのものを見たほうが先方もわかりやすいはずと勝手に決め込んでwinkを使用した。


久々に使ってまず驚いたのがメニューに日本語が選択できるようになっていたこと。一々メニューの項目の意味をgooさんに問い合わせなくてよくていい感じ。


それと"タイムキャプチャ"なる機能が発見。
以前は手動でキャプチャをとりたいところでキー操作してキャプチャをとり、キャプチャの間を補完するアニメーションをアプリケーションが作ってくれる(カーソルの動きなど)という感じで使っていたのだが、"タイムキャプチャ"はアプリケーションが自動でキャプチャをとっていってくれるのでとても便利だった。


ただいいことばかりではなく説明書きの日本語を打ち込んだときフォントが90度回転して入力されるのは直ってなかった。これはOpen Typeのフォントを使うと正常に入力される。


とりあえずサクっと作った割にはいい感じにできた。今度からこういう仕事はwinkでしよう。

図形描画クラス(軽量アルミとポリカーボネイト)

描画


前回のエントリで使った図形描画クラスで他の素材感も出してみた

import jp.ojos.tools.Shapes;

var rgb = 0x000000;
var rgb2 = 0x666666;
var __width = 200;
var __height = 50;
var __x = 100;
var __y1 = 50;
var __y2 = 150;
var __y3 = 250;



//aqua風

Shapes.drawRoundRect(this, __x, __y1, __width, __height, __height / 2,0x000000,15);
Shapes.drawRoundRect(this, __x + 1, __y1 + 1, __width - 2, __height - 2, (__height - 1) /2,rgb,100);
Shapes.drawRoundRect(this, __x + 1, __y1 + 1, __width - 2, __height - 2, (__height - 1) /2,[0xffffff,0xffffff],[0,100],
{matrixType:"box", x:__x + 1, y:__y1 + 1, w:__width - 2, h:__height - 2, r:(90/180)*Math.PI},"linear",
[130,255]);
Shapes.drawRoundRect(this, __x + (__height - 2) / 4,
__y1 + 1,
__width - (__height - 2) / 2,
(__height - 2) / 2,
(__height - 2) / 4,
[0xffffff,0xffffff],
[100,0],
{matrixType:"box", x:__x + (__height - 2) / 4,
y:__y1 + 1,
w:__width - (__height - 2) / 2,
h:(__height - 2) / 2,
r:(90/180)*Math.PI},"linear");

//メタル風
Shapes.drawRoundRect(this, __x, __y2, __width, __height, __height / 2,0x000000,50);
Shapes.drawRoundRect(this, __x + 2, __y2 + 2, __width - 4, __height - 4, (__height - 2) /2,0xffffff,70);
Shapes.drawRoundRect(this, __x + 2, __y2 + 2, __width - 4, __height - 4, (__height - 2) /2,[0xffffff,0xffffff],[100,0],
{matrixType:"box", x:__x + 2, y:__y2 + 2, w:__width - 4, h:__height - 4, r:(90/180)*Math.PI},"linear",
[0,150]);



//ポリカーボネイト風
Shapes.drawRoundRect(this, __x, __y3, __width, __height, __height / 2,rgb,65);
Shapes.drawRoundRect(this, __x + 2, __y3 + 2, __width - 4, __height - 4, (__height - 2) /2,rgb2,100);
Shapes.drawRoundRect(this, __x + 2, __y3 + 2, __width - 4, __height - 4, (__height - 2) /2,[0xffffff,0xffffff],[70,0],
{matrixType:"box", x:__x + 2, y:__y3 + 2, w:__width - 4, h:__height - 4, r:(90/180)*Math.PI},"linear",
[0,120]);

流行にのってみた。

図形描画クラス(aquaボタン描画)

ほぼまんまパクりだけどのっけとく

/**
*
* 図形描画クラス
*
* @author aizu
* @version 0.1.0
*/
class jp.ojos.tools.Shapes {

/**
*
* 楕円作成
*
* @param x 楕円の中心のx座標
* @param y 楕円の中心のy座標
* @param w 幅の半径
* @param h 高さの半径
* @param c 塗りの色(number or array [0x######,0x######])
* @param alpha アルファ値
* @param rot 変換マトリックス(詳細 : ActionScript クラス > MovieClip > beginGradientFill 参照 )
* @param gradient グラデーションタイプ("linear" or "radial")
* @param ratios Transform値(省略可:デフォルト[0,255])
*
* Example
*
* import jp.ojos.tools.Shapes;
* Shapes.drawOval(this, 200, 200, 200, 200, [0xff0000e, 0x00ff00], 100, 20, "linear");
*/

static function drawOval(target : Object,
x : Number,
y : Number,
w : Number,
h : Number,
c : Object,
alpha : Object,
rot : Object,
gradient : String,
ratios : Object) : Void {
// if color is an object then allow for complex fills
if(typeof c == "object")
{
if (typeof alpha != "object")
var alphas : Object = [alpha,alpha];
else
var alphas : Object = alpha;

if (ratios == undefined)
var ratios : Array = [ 0, 0xff ];

var sh : Number = h *.7;
if (typeof rot != "object")
var matrix : Object = {matrixType:"box", x:-sh, y:sh, w:w*2, h:h*4, r:rot * 0.0174532925199433 };
else
var matrix : Object = rot;

if (gradient == "radial")
target.beginGradientFill( "radial", c, alphas, ratios, matrix );
else
target.beginGradientFill( "linear", c, alphas, ratios, matrix );

}
else if (c != undefined)
{
target.beginFill (c, alpha);
}



var j : Number = w*0.70711;
var n : Number = h*0.70711;
var i : Number = j-(h-n)*w/h;
var m : Number = n-(w-j)*h/w;

target.moveTo(x+w, y);
target.curveTo(x+w, y-m, x+j, y-n);
target.curveTo(x+i, y-h, x, y-h);
target.curveTo(x-i, y-h, x-j, y-n);
target.curveTo(x-w, y-m, x-w, y);
target.curveTo(x-w, y+m, x-j, y+n);
target.curveTo(x-i, y+h, x, y+h);
target.curveTo(x+i, y+h, x+j, y+n);
target.curveTo(x+w, y+m, x+w, y);

if (c != undefined)
target.endFill();
}

/**
*
* 長方形(角丸も可)作成
*
* @param x x座標
* @param y y座標
* @param w 幅
* @param h 高さ
* @param r 角の丸み(number or object {br:#,bl:#,tl:#,tr:#})
* @param c 塗りの色(number or array [0x######,0x######])
* @param alpha アルファ値
* @param rot 変換マトリックス(詳細 : ActionScript クラス > MovieClip > beginGradientFill 参照 )
* @param gradient グラデーションタイプ("linear" or "radial")
* @param ratios Transform値(省略可:デフォルト[0,255])
*
* Example
*
* import jp.ojos.tools.Shapes;
* Shapes.drawRoundRect(this, 0, 0, 400, 400, {tl:10,tr:10,br:0,bl:0},[0xff0000e,0x00ff00],100,20,"linear");
*/

static function drawRoundRect(target : Object,
x : Number,
y : Number,
w : Number,
h : Number,
r : Object,
c : Object,
alpha : Object,
rot : Object,
gradient : String,
ratios : Object) : Void {
if (typeof r == "object") {
var rbr : Object = r.br; //bottom right corner
var rbl : Object = r.bl; //bottom left corner
var rtl : Object = r.tl; //top left corner
var rtr : Object = r.tr; //top right corner
}
else
{
var rbr : Object = rbl = rtl = rtr = r;
}
// if color is an object then allow for complex fills
if(typeof c == "object")
{
if (typeof alpha != "object")
var alphas : Object = [alpha,alpha];
else
var alphas : Object = alpha;

if (ratios == undefined)
var ratios : Array = [ 0, 0xff ];

var sh : Number = h *.7;
if (typeof rot != "object")
var matrix : Object = {matrixType:"box", x:-sh, y:sh, w:w*2, h:h*4, r:rot * 0.0174532925199433 };
else
var matrix : Object = rot;

if (gradient == "radial")
target.beginGradientFill( "radial", c, alphas, ratios, matrix );
else
target.beginGradientFill( "linear", c, alphas, ratios, matrix );

}
else if (c != undefined)
{
target.beginFill (c, alpha);
}

// Math.sin and Math,tan values for optimal performance.
// Math.rad = Math.PI/180 = 0.0174532925199433
// r*Math.sin(45*Math.rad) = (r*0.707106781186547);
// r*Math.tan(22.5*Math.rad) = (r*0.414213562373095);

//bottom right corner
r = rbr;
var a : Number = r - (r*0.707106781186547); //radius - anchor pt;
var s : Number = r - (r*0.414213562373095); //radius - control pt;
target.moveTo ( x+w,y+h-r);
target.lineTo ( x+w,y+h-r );
target.curveTo( x+w,y+h-s,x+w-a,y+h-a);
target.curveTo( x+w-s,y+h,x+w-r,y+h);

//bottom left corner
r = rbl;
var a : Number = r - (r*0.707106781186547);
var s : Number = r - (r*0.414213562373095);
target.lineTo ( x+r,y+h );
target.curveTo( x+s,y+h,x+a,y+h-a);
target.curveTo( x,y+h-s,x,y+h-r);

//top left corner
r = rtl;
var a : Number = r - (r*0.707106781186547);
var s : Number = r - (r*0.414213562373095);
target.lineTo ( x,y+r );
target.curveTo( x,y+s,x+a,y+a);
target.curveTo( x+s,y,x+r,y);

//top right
r = rtr;
var a : Number = r - (r*0.707106781186547);
var s : Number = r - (r*0.414213562373095);
target.lineTo ( x+w-r,y );
target.curveTo( x+w-s,y,x+w-a,y+a);
target.curveTo( x+w,y+s,x+w,y+r);
target.lineTo ( x+w,y+h-r );

if (c != undefined)
target.endFill();
}
}

でこれで一時期はやったアクアボタンをスクリプトだけで描く。
これもほとんどパクりだけど気にしない。

import jp.ojos.tools.Shapes;

var rbg = 0xcccccc;
var __width = 100;
var __height = 22;
var __x = 0;
var __y = 0;

Shapes.drawRoundRect(this, __x, __y, __width, __height, __height / 2,0x000000,15);
Shapes.drawRoundRect(this, __x + 1, __y + 1, __width - 2, __height - 2, (__height - 1) /2,rbg,100);
Shapes.drawRoundRect(this, __x + 1, __y + 1, __width - 2, __height - 2, (__height - 1) /2,[0xffffff,0xffffff],[0,100],
{matrixType:"box", x:__x + 1, y:__y + 1, w:__width - 2, h:__height - 2, r:(90/180)*Math.PI},"linear",
[130,255]);
Shapes.drawRoundRect(this, __x + (__height - 2) / 4,
__y + 1,
__width - (__height - 2) / 2,
(__height - 2) / 2,
(__height - 2) / 4,
[0xffffff,0xffffff],
[100,0],
{matrixType:"box", x:__x + (__height - 2) / 4,
y:__y + 1,
w:__width - (__height - 2) / 2,
h:(__height - 2) / 2,
r:(90/180)*Math.PI},"linear");

Flashで依存注入してみました

前々から気になっていたDI。
でも自分の技術レベルが伴わずSeaser2のドキュメントを何度読んでも理解不能でしたが、以前紹介したこれと昨日買ったこの本

Seasar入門 はじめてのDI&AOP

Seasar入門 はじめてのDI&AOP

を読んでたら

なんかDIってStrategyパターンと一緒じゃね?

と思い始めて今作っている時計をDI仕様にしてみた。
(と本人は思っている)

こんな風に書く

var DIAnalog_mc : Analog = new Analog();
DIAnalog_mc.create(this,1);
DIAnalog_mc.move(400,300,2,0,Bounce.easeOut);
var bg_mc = DIAnalog_mc.setBgMC(new Frame());
bg_mc.setDrawBehavior(new WindowFrame(),100,100);
bg_mc.move(-(bg_mc._width/2),-(bg_mc._height/2));
DIAnalog_mc.setHourMC("hour_mc");
DIAnalog_mc.setMinuteMC("minute_mc");
DIAnalog_mc.setSecondMC("Second_mc");
DIAnalog_mc.setSurfaceMC("surface_mc");
DIAnalog_mc.start();

複数ファイルで構成されているからコードベタ張りできないな。
自宅サーバは死んでるし、会社のサーバーはまずいだろ。
どうしようかな。


●追記
とりあえずここにアップ。(Not Foundになってたのを修正)
clock.zip



●追記の追記
やはりこんな過疎blogでは反応がない。
自分のやっていることが果たして有用かどうか誰かに評価してもらいたいのだが...。
こうなったら手当たり次第にアルファフラッシャー(安易なネーミング)送りつけてみるか。