私は質問がありました:AS 3.ドラッグ可能なポストイットのノートムービークリップを作成しました。ノートのパッド全体を作成するか、少なくともこれをシミュレートします。これを行う最善の方法は、startDrag()が起動されるたびに別のPost-Itを追加することだと思いました。MCの複数のコピーを動的にインスタンス化する
私は最初に記号でポストイットを作成しようとしましたが、この方法で新しいものを動的に作成することはできませんでした。その後、クラスを作成してステージに追加しました。
... addChild(新しいPostItNote());
しかし、ステージ上のx、yの位置を設定することができませんでした(またはわからない)。
誰かが、これを達成するための最良の方法、あるいは別の方法を提案していますか?
EDIT:
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.text.TextField;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.text.TextFormat;
public class CoinHitTest extends MovieClip {
var count:Number = 0;
var total_count:TextField;
var hitting:Boolean = false;
var coinSnd:Sound = new coin_drop();
var myMoney:TextFormat = new TextFormat();
var noteStack:Vector.<PostItNotes> = new Vector.<PostItNotes>();
public function CoinHitTest(){
for(var $i:int = 0; $i <5;$i++)
{
var newPostIt:PostItNotes = new PostItNotes();
this.addChild(newPostIt);
this.noteStack.push(newPostIt);
}
// constructor code
coin.addEventListener(MouseEvent.MOUSE_DOWN, __handleCoinDown);
coin.addEventListener(MouseEvent.MOUSE_UP, __handleCoinUp);
total_count = new TextField();
total_count.x = 795.20;
total_count.y = 506.15;
total_count.mouseEnabled = false;
myMoney.size = 28;
total_count.defaultTextFormat = myMoney;
total_count.text = String("$" + count);
addChild(total_count);
}
private function __handleCoinDown($evt:MouseEvent):void {
coin.startDrag(true);
coin.scaleX = 1.5;
coin.scaleY = 1.5;
addEventListener(Event.ENTER_FRAME, __checkHit);
}
private function __handleCoinUp($evt:MouseEvent):void {
coin.stopDrag();
coin.scaleX = 1;
coin.scaleY = 1;
removeEventListener(Event.ENTER_FRAME, __checkHit);
}
private function __checkHit($evt:Event):void {
if (this.coffee.hitTestPoint(coin.x,coin.y, false))
{
// do our in-circle check
if((coffee.x - coin.x) * 2 + (coffee.y - coin.y) * 2 <= (coffee.width/2 + coin.width/2) * 2)
{
stopDrag();
coin.scaleX = 1;
coin.scaleY = 1;
removeChild(coin);
coin.x = 116;
coin.y = 380.1;
addChild(coin);
}
}
else
{
trace("Didn't Hit Mug");
}
if (this.coin.hitTestObject(target)) {
if (!hitting) {
coinSnd.play();
count++;
total_count.text = String("$" + count);
coin.stopDrag();
removeChild(coin);
hitting = !hitting;
coin.x = 116;
coin.y = 380.1;
addChild(coin);
coin.scaleX = 1;
coin.scaleY = 1;
}
} else {
hitting = false;
}
}
}
}
はEDIT:
package {
import flash.display.MovieClip;
public class PostItNotes extends Sprite{
public function PostItNotes() {
// constructor code
}
}
}
近づいて...私は思う。問題は、私のドラッグアンドドロップは、コード内に作成されたシンボルではなく、ステージ上に配置されたシンボルでのみ機能することです。私はシンボル上にドラッグ&ドロップのコードスニペットを使用しました。 – Casey
質問をもう一度編集し、作成したPostItNotesクラスのコードを投稿してください。 – Mathias
私のPostItNotesクラスをペーストしました。あなたが見るように、空になっているのは、その中にあったすべてが描画メソッドであったからです。ステージ上のシンボルとクラスを削除したので、削除しました。私はこのクラスに何かを持っているべきですか? – Casey