几年前发布了一个非常类似的问题,这个有用的答案让我了解了解的一部分,但作为AS3的新手,我需要更多帮助才能达到终点。
这是我尝试做的事情:
我认为它可能会是这样的:
if (time==0 && itemsToSort >0) {
goToAndPlay (2, "Try Again!");
}
if (time==0 && itemsToSort <1){
goToAndPlay (5, "Great job!")
cheer.play();
}
我还没有设置一个数组我还没定义什么时间和项目代表的意思,我不确定上述是否有效,或者在下面的代码中我应该在哪里如果能起作用的话就说出来。
stop();
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.media.Sound;
var objectoriginalX:Number;
var objectoriginalY:Number;
var correct:Sound = new Toss();
var incorrect:Sound = new Swoosh();
var background:Sound = new Background();
cstrawberry.buttonMode = true;
cstrawberry.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
cstrawberry.addEventListener(MouseEvent.MOUSE_UP, dropObject);
csandwich.buttonMode = true;
csandwich.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
csandwich.addEventListener(MouseEvent.MOUSE_UP, dropObject);
cnapkin.buttonMode = true;
cnapkin.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
cnapkin.addEventListener(MouseEvent.MOUSE_UP, dropObject);
rbottle.buttonMode = true;
rbottle.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
rbottle.addEventListener(MouseEvent.MOUSE_UP, dropObject);
rcup.buttonMode = true;
rcup.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
rcup.addEventListener(MouseEvent.MOUSE_UP, dropObject);
rfoil.buttonMode = true;
rfoil.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
rfoil.addEventListener(MouseEvent.MOUSE_UP, dropObject);
lspork.buttonMode = true;
lspork.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
lspork.addEventListener(MouseEvent.MOUSE_UP, dropObject);
ljuice.buttonMode = true;
ljuice.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
ljuice.addEventListener(MouseEvent.MOUSE_UP, dropObject);
lyogurt.buttonMode = true;
lyogurt.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
lyogurt.addEventListener(MouseEvent.MOUSE_UP, dropObject);
background.play();
function hover(event:MouseEvent):void {
this.filters = [ new DropShadowFilter() ];
}
function pickupObject(event:MouseEvent):void {
event.target.startDrag(true);
event.target.parent.addChild(event.target);
objectoriginalX = event.target.x;
objectoriginalY = event.target.y;
}
function dropObject(event:MouseEvent):void {
event.target.stopDrag();
//check if the leading Letter for both Sprites is the same
if (testIfMatch(event.target.name, event.target.dropTarget.parent.name)){
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
event.target.removeEventListener(MouseEvent.MOUSE_UP, dropObject);
event.target.buttonMode = false;
event.target.visible = false;
correct.play();
}else{
event.target.x = objectoriginalX;
event.target.y = objectoriginalY;
incorrect.play();
}
}
function testIfMatch(_drop:String, _target:String):Boolean {
if (_drop.substr(0, 1) == _target.substr(0, 1)) {
return true;
} else{
return false
}
}
答案 0 :(得分:0)
如果您希望有一个剩余时间的可视指示器,使用Timer
可能无法为您提供所需的灵活性。此外,您需要注册mouseOver
和mouseOut
事件的按钮才能应用DropShadow。
stop();
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.media.Sound;
var objectoriginalX:Number;
var objectoriginalY:Number;
var correct:Sound = new Toss();
var incorrect:Sound = new Swoosh();
var background:Sound = new Background();
// For convenience (and lookup later), we add the buttons to an array.
var btnArray = [cstrawberry, csandwich, cnapkin, rbottle, rcup, rfoil, lspork, ljuice, lyogurt];
// Loop through the array, and register each to the events we need.
for each (var button in btnArray) {
button.buttonMode = true;
button.addEventListener("mouseOver", buttonEvents);
button.addEventListener("mouseOut", buttonEvents);
button.addEventListener("mouseDown", buttonEvents);
button.addEventListener("mouseUp", buttonEvents);
}
background.play();
function buttonEvents(e:MouseEvent):void {
// Here we handle all button states
// Simplify references to the current button by creating a local var.
var btn:MovieClip = e.currentTarget as MovieClip;
switch (e.type) {
case "mouseOver":
// Show the dropdown.
btn.filters = new Array(new DropShadowFilter(10, 90, 0, 0.25, 10, 10));
break;
case "mouseOut":
// Hide the dropdown
btn.filters = new Array(new DropShadowFilter(0, 90, 0, 0, 10, 10));
break;
case "mouseDown":
// Drag the button and store the original locs
btn.startDrag(true);
btn.parent.addChild(btn);
objectoriginalX = btn.x;
objectoriginalY = btn.y;
break;
case "mouseUp":
// Drop the drag, and evaluate if it was correct
btn.stopDrag();
if (testIfMatch(btn.name, btn.dropTarget.parent.name)){
btn.removeEventListener("mouseDown", pickupObject);
btn.removeEventListener("mouseUp", dropObject);
btn.buttonMode = false;
btn.visible = false;
correct.play();
} else {
btn.x = objectoriginalX;
btn.y = objectoriginalY;
incorrect.play();
}
break;
}
}
function testIfMatch(_drop:String, _target:String):Boolean {
//check if the leading Letter for both Sprites is the same
if (_drop.substr(0, 1) == _target.substr(0, 1)) {
return true;
} else {
return false ;
}
}
// Let's create something to look at the countdown.
var countdownTime:int = 30;
var countdown:TextField = new TextField();
countdown.text = "Time: " + countdownTime;
addChild(countdown);
stage.addEventListener(Event.ENTER_FRAME, updateCounter);
var lastSecond:Number = flash.utils.getTimer();
function updateCounter(e:Event):void {
var now:Number = flash.utils.getTimer();
// If more than one second has past, reset the lastSecond to now, and update the counter.
if (now - lastSecond > 1000) {
lastSecond += 1000;
countdownTime--;
countdown.text = "Time: " + countdownTime;
if (countdownTime < 1) {
stage.removeEventListener(Event.ENTER_FRAME, updateCounter);
// Count how many are still visible
var visibleButtons:int = 0;
for each (btn in btnArray) {
if (btn.visible) {
visibleButtons++;
}
}
if (visibleButtons > 0) {
goToAndPlay (2, "Try Again!");
} else {
goToAndPlay (5, "Great job!")
cheer.play();
}
}
}
}