Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
//Referenz speichern
a1.targetSpot = anySprite;
//Vergleichen
var currentClip: Sprite = event.currentTarget as Sprite;
if (currentClip.dropTarget && currentClip.dropTarget == currentClip.targetSpot) {
//Anweisungen
}
//Erstelle Instanzen
var target1: MovieClip = getSquare(0x990000, .4, 100);
target1.x = 80;
target1.y = 80;
addChild(target1);
var target2: MovieClip = getSquare(0x009900, .4, 100);
target2.x = 200;
target2.y = 80;
addChild(target2);
var target3: MovieClip = getSquare(0x000099, .4, 100);
target3.x = 320;
target3.y = 80;
addChild(target3);
var dropper1: MovieClip = getSquare(0x990000, 1, 100);
dropper1.x = 80;
dropper1.y = 180;
addChild(dropper1);
var dropper2: MovieClip = getSquare(0x009900, 1, 100);
dropper2.x = 200;
dropper2.y = 180;
addChild(dropper2);
var dropper3: MovieClip = getSquare(0x000099, 1, 100);
dropper3.x = 320;
dropper3.y = 180;
addChild(dropper3);
//Weise jedem dropper sein gültiges dropTarget zu:
dropper1.targetSpot = target1;
dropper2.targetSpot = target2;
dropper3.targetSpot = target3;
//MouseDown-Listener für jeden dropper
dropper1.addEventListener ("mouseDown", startDragging);
dropper2.addEventListener ("mouseDown", startDragging);
dropper3.addEventListener ("mouseDown", startDragging);
//MouseUp-Listener für jeden dropper
dropper1.addEventListener ("mouseUp", stopDragging);
dropper2.addEventListener ("mouseUp", stopDragging);
dropper3.addEventListener ("mouseUp", stopDragging);
//MouseDown-Funktion
function startDragging(a_event: Event): void {
var dropper: MovieClip = a_event.currentTarget as MovieClip;
dropper.startDrag(true);
}
//MouseUp-Funktion
function stopDragging(a_event: Event): void {
var dropper: MovieClip = a_event.currentTarget as MovieClip;
dropper.stopDrag();
if (dropper.dropTarget && dropper.dropTarget == dropper.targetSpot) {
dropper.x = dropper.targetSpot.x;
dropper.y = dropper.targetSpot.y;
dropper.removeEventListener("mouseDown", startDragging);
dropper.removeEventListener("mouseUp", stopDragging);
}
}
//Hilfsfunktion für Quadraterstellung
function getSquare (a_color: uint, a_alpha: Number, a_size: Number): MovieClip {
var s: MovieClip = new MovieClip ();
with (s.graphics) {
beginFill(a_color, a_alpha);
drawRect(-a_size/2, -a_size/2, a_size, a_size);
endFill();
}
return s;
}