RSS | Twitter | Facebook
Home » ActionScript » graphic » image » 外部画像の表示 : ActionScript

外部画像の表示 : ActionScript

外部画像を読み込んで表示するサンプル。

640×480の画像を読み込んで320×240のサイズに調整して配置。

1) 空のムービークリップを2個作成し、入れ子に配置する(親,子)
2) 子クリップに画像を読み込む(子.loadMovie(’filename’))。
3) 読み込んだ画像の幅や高さは、読み込み完了後の親クリップの幅、高さを取得することにより得られる。子クリップの幅、高さは、常に画像を読み込む前のクリップの幅、高さの値が帰る。
4) 親クリップの幅、高さは、画像の読み込み前は0、読み込み完了後は読み込んだ画像のサイズとなる。読み込みを完了するにはタイムラグがある。親クリップのonEnterFrameイベントハンドラ内で幅、高さを監視する。

function Image() {
	this.init = function(child, parent) {
		child.loadMovie('01.jpg');
		parent.onEnterFrame = sizing;
	};
	var sizing = function () {
		//読み込み判定
		if (!this._width == 0 || !this._height == 0) {
			var scaleX = 320*100/this._width;
			var scaleY = 240*100/this._height;
			var scale = 0;
			if (scaleX>scaleY) {
				scale = scaleY;
			} else {
				scale = scaleX;
			}
			this._xscale = scale;
			this._yscale = scale;
			delete this.onEnterFrame;
			// 中央配置
			this._x = (Stage.width-this._width)/2;
			this._y = (Stage.height-this._height)/2;
		}
	};
}
var parent = _root.createEmptyMovieClip("p", _root.getNextHighestDepth());
var child = parent.createEmptyMovieClip("c", e.getNextHighestDepth());
var o = new Image();
o.init(child, parent);

個人的メモ

1) _framesloadedプロパティを使ったがうまくできなかった。
2) 画像を読み込むムービークリップは、画像が読み込まれた時点でonEnterFrameなどのイベントハンドラが使えなくなる。
3) WordPressでは読み込みパスをurlにする。

このページの上へ移動

  Yahoo!ブックマークに登録    Google  この記事をクリップ!  BuzzurlにブックマークBuzzurlにブックマーク

2008/6/2 月 | image | 固定リンク |

コメントはまだありません。

コメントの投稿

改行と段落タグは自動で挿入されます。メールアドレスは表示されません。
利用可能な HTML タグ :
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite="">
<cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(必須)

(必須)


トラックバックURL

このページの上へ移動