dポイントプレゼントキャンペーン実施中!

ただ今flash勉強中の初心者です。検索したり本を調べたりしても根本が理解できていないためか、解答策が見つからず困っています。
自分で作ったものではないのですが、1フレーム目にActionを書いています。動きとしては、テレビの砂嵐のような画面に、二種類の文字がランダムに出て、ラインもランダムに出てくるという感じです。以下のscriptだと永遠と続くのですが、5秒ぐらいランダムに文字とラインが出て、その後砂嵐の画面だけにして止めたいのですが、どうしたら良いかわかりません。
使用しているソフトはFlash8、MacOSX10.4です。

import flash.display.BitmapData;
var tv_noise:BitmapData = new BitmapData(Stage.width,Sage.height,true);
_root.attachBitmap(tv_noise,20);
_root.attachMovie("text1","text_1",3);
_root["text_1"].scale = 350;
_root["text_1"].onEnterFrame = random_me;
_root.attachMovie("text2","text_2",2);
_root["text_2"].scale = 350;
_root["text_2"].onEnterFrame = random_me;
_root.attachMovie("line","line_1",1);
_root["line_1"]._y = Stage.height/2;
_root["line_1"]._alpha = 40;
_root["line_1"].onEnterFrame = scale_me;

function random_me():Void{
this._x = 10+Math.round(Math.random()*Stage.width);
this._y = 10+Math.round(Math.random()*Stage.height);
this._xscale = this._yscale = Math.round(Math.ramdom() *this.scale);
this._alpha = 10+Math.round(Math.random()*100);
}
function scrach_me():Void{
this._x = 10+Math.round(Math.random()*Stage.width);
tv_noise.noise(Math.round(Math.random()*100000),80,170,8,true);
}
宜しくお願いします。

A 回答 (1件)

ユーザ定義関数 scale_me が抜けていたり,


他にも抜けている項目が多々ありますから検証できませんので,

「5秒ぐらいランダムに文字が出て、その後砂嵐の画面だけにする」
という文字に関してのみ回答します。

つまり,
文字以外のスクリプトは全て排除した状態↓


_root.attachMovie("text1","text_1",3);
_root["text_1"].scale = 350;
_root["text_1"].onEnterFrame = random_me;
_root.attachMovie("text2","text_2",2);
_root["text_2"].scale = 350;
_root["text_2"].onEnterFrame = random_me;

function random_me():Void{
this._x = 10+Math.round(Math.random()*Stage.width);
this._y = 10+Math.round(Math.random()*Stage.height);
this._xscale = this._yscale = Math.round(Math.ramdom() *this.scale);
this._alpha = 10+Math.round(Math.random()*100);
}


これを書き替えます↓。

------------------------------
// 変数 count の初期化
var count:Number = 0;
_root.attachMovie("text1", "text_1", 3);
_root["text_1"].scale = 350;
_root["text_1"].onEnterFrame = random_me;
_root.attachMovie("text2", "text_2", 2);
_root["text_2"].scale = 350;
_root["text_2"].onEnterFrame = random_me;

function random_me():Void {
// count を 1 加算
count += 1;
// count が 120 以下のとき
if (count<=120) {
// 表示状態にする
this._visible = true;
this._x = 10+Math.round(Math.random()*Stage.width);
this._y = 10+Math.round(Math.random()*Stage.height);
this._xscale = this._yscale=Math.round(Math.random()*this.scale);
this._alpha = 10+Math.round(Math.random()*100);
} else if (count<=240) {
// count が 240 以下のとき 非表示状態にする
this._visible = false;
} else {
// count を 0 に戻す
count = 0;
}
}
---------------------------------



その他,細かい点。
書かれているスクリプトの2行目

 …new BitmapData(Stage.width,Sage.height,true);

Sage.height ではなくて,
Stage.height だと思いますよ。


それと下の方,

 this._xscale = this._yscale = Math.round(Math.ramdom() *this.scale);

Math.ramdom() *this.scale ではなくて
Math.random() *this.scale だと思いますよ。

他もあるのかもしれませんが,
とにかく再現できませんのでその他何処にミスがあるのかはわかりません。

線に関して実行される,
ユーザ定義関数 scale_me も同様に修正すれば良いとは思います。
    • good
    • 0
この回答へのお礼

スクリプトの記述ミス、すみませんでした。見直したのに抜けていました。そういう点から勉強し直さないといけないようです。
丁寧に教えていただきまして、ありががとうございます。
記述とおりやってみたところ出来ました。^^
countを0に戻さなければずっと非表示のままですね。
また分岐処理を変えてやれば、他の動きもできますよね。
何日も考えていたことが、アッという間に解決でき嬉しいのと共にもっといろいろな事をやってみたいと思います。
Flashは難しいなぁ、と頭をかかえていましたが少し希望がわいてきました。もっと頑張って自分で一からスクリプトが書けるよう頑張ります。
この度は、ありがとうございました。

お礼日時:2007/04/08 20:43

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!