スキップメニュー:コンテンツへナビゲーションへ

乱雑モックアップ   らんざつ[乱雑] (名・形動)[文]ナリ 入り乱れていること。乱れていて秩序がないこと。また、そのさま。

重なり順関係

2009年 7月 27日 |

as3, flash |

このエントリをはてなブックマークに追加このエントリをdel.icio.usに追加このエントリをLivedoor Clipに追加このエントリーのブックマーク数

下準備
stageにp0-p4まで適当なmcを作って微妙に重ねて配置

var photonum:Array = [];
var photomax = 5;

for (var i:int=0; i<photomax ; i++) {
	photonum[i] = "p" + i;
	this[photonum[i]].addEventListener(MouseEvent.CLICK,getindex);
}

function getindex(e:MouseEvent) {
	var nummax:int = numChildren;
	trace("nummax/"+nummax);
	var owner=e.currentTarget;
	trace("owner/"+e.currentTarget);
	trace(getChildIndex(owner));
	setChildIndex(owner,nummax-1)
}

動的に四角を作ってみる

var photonum:Array = [];
var photomax = 5;
var mySprites;

for (var i:Number=0; i<photomax; i++) {
	var rectcolor:uint = Math.floor(Math.random() * 0xffffff);
	mySprites=new Sprite();
	mySprites.graphics.beginFill(rectcolor);
	mySprites.graphics.drawRect((40*i)+10,(40*i)+10,100,100);
	mySprites.graphics.endFill();
	addChild(mySprites);

	mySprites.addEventListener(MouseEvent.CLICK,getindex2);
}
function getindex2(e:MouseEvent) {
	var nummax:Number = numChildren;
	trace("nummax/"+nummax);
	var owner = e.currentTarget;
	trace("owner/"+e.currentTarget);
	trace(getChildIndex(owner));
	setChildIndex(owner,nummax-1);
}

最初Shapeで四角を作っていたのだけれど、どうもうまくいかない(addEventListenerを設定できない)

as3に慣れてないから、自分の書いたソースのどこが間違ってるの全然わからない><
とりあえずShapeがアヤシイとめぼしをつけて調べてみる

Sprite クラスにも graphics プロパティがあり、これには Shape クラスでは使用できない他の機能があります。 例えば、Sprite オブジェクトは表示オブジェクトコンテナであるのに対し、Shape オブジェクトはそうではありません(子表示オブジェクトも持てません)。したがって、表示するグラフィックスが同じであっても、Sprite オブジェクトは、Shape オブジェクトよりも多くのメモリを消費します。ただし、Sprite オブジェクトではマウスクリックイベントがサポートされますが、Shape オブジェクトではサポートされません。

との事。
なのでshapeをやめてspriteにしたら、マウスに反応した。
簡単な事なのに躓いてばかりだ。

for文の中で何回も同じ
mySprites=new Sprite();
でmySpritesを作成してaddChildしてるけど、これは問題ないのだろうか?
なんで上書きにならないんだろう


メモ(あとでnumChildrenとかsetchildIndexとか調べる時用)
ActionScript3.0逆引きクイックリファレンスp161
「a92、表示オブジェクトの重なり順をコントロールするには」


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

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

この投稿へのコメントの RSS フィード。 TrackBack URL

コメントする

You can add images to your comment by clicking here.




Back to Top↑

あわせて読みたい

Back to Top↑

RSS 乱雑モックアップのフィード

Copyright © 乱雑モックアップ. All Rights Reserved.