拖放匹配类型游戏与闪存中的分组

时间:2011-10-28 06:00:00

标签: flash actionscript-3 actionscript flash-cs5

对不起我的程序中的误解,我在这里很新,我也是使用flash的新手。这是我在代码中使用的示例输出

![样本输出(http://i1114.photobucket.com/albums/k532/deadmaster2903/sample.jpg)


这是我使用的代码:

 var objectoriginalX:Number;
 var objectoriginalY:Number;
 var score:Number = 0;
 var count:Number = 30;
 var myTimer:Timer = new Timer(1000,count);
 myTimer.addEventListener(TimerEvent.TIMER, countdown);
 myTimer.start();
 if (myText_txt.text == "0")
 {
myText_txt.text ="Times Up!";
 }
 function countdown(event:TimerEvent):void
 {
myText_txt.text = String((count)-myTimer.currentCount);
 }
 //fall
 fallapple_mc.buttonMode = true;
 fallapple_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 fallapple_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 fallchicory_mc.buttonMode = true;
 fallchicory_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 fallchicory_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 fallchilipeppers_mc.buttonMode = true;
 fallchilipeppers_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 fallchilipeppers_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 fallchinesecabbage_mc.buttonMode = true;
 fallchinesecabbage_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 fallchinesecabbage_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 fallcranberries_mc.buttonMode = true;
 fallcranberries_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 fallcranberries_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 fallcucumber_mc.buttonMode = true;
 fallcucumber_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 fallcucumber_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 falldates_mc.buttonMode = true;
 falldates_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 falldates_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 fallgrapes_mc.buttonMode = true;
 fallgrapes_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 fallgrapes_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 fallleaflettuce_mc.buttonMode = true;
 fallleaflettuce_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 fallleaflettuce_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 fallnuts_mc.buttonMode = true;
 fallnuts_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 fallnuts_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 fallpersimmon_mc.buttonMode = true;
 fallpersimmon_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 fallpersimmon_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 fallpomegranates_mc.buttonMode = true;
 fallpomegranates_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 fallpomegranates_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 //spring
 springasparagus_mc.buttonMode = true;
 springasparagus_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 springasparagus_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 springbasil_mc.buttonMode = true;
 springbasil_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 springbasil_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 springbeans_mc.buttonMode = true;
 springbeans_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 springbeans_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 springbeets_mc.buttonMode = true;
 springbeets_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 springbeets_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 springberries_mc.buttonMode = true;
 springberries_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 springberries_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 springiceberg_mc.buttonMode = true;
 springiceberg_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 springiceberg_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 springmango_mc.buttonMode = true;
 springmango_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 springmango_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 springpapaya_mc.buttonMode = true;
 springpapaya_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 springpapaya_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 springpeas_mc.buttonMode = true;
 springpeas_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 springpeas_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 springradish_mc.buttonMode = true;
 springradish_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 springradish_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 springrhubarb_mc.buttonMode = true;
 springrhubarb_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 springrhubarb_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 springshallots_mc.buttonMode = true;
 springshallots_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 springshallots_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 //summer
 summerapricot_mc.buttonMode = true;
 summerapricot_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 summerapricot_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 summerbellpepper_mc.buttonMode = true;
 summerbellpepper_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 summerbellpepper_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 summerbrocolli_mc.buttonMode = true;
 summerbrocolli_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 summerbrocolli_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 summercherries_mc.buttonMode = true;
 summercherries_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 summercherries_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 summercorn_mc.buttonMode = true;
 summercorn_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 summercorn_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 summerfigs_mc.buttonMode = true;  
 summerfigs_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 summerfigs_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 summerokra_mc.buttonMode = true;
 summerokra_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 summerokra_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 summerpeaches_mc.buttonMode = true;
 summerpeaches_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 summerpeaches_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 summerplum_mc.buttonMode = true;
 summerplum_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 summerplum_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 summersquash_mc.buttonMode = true;
 summersquash_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 summersquash_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 summertomato_mc.buttonMode = true;
 summertomato_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 summertomato_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 summerwatermelon_mc.buttonMode = true;
 summerwatermelon_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 summerwatermelon_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 //winter
 winteravocado_mc.buttonMode = true;
 winteravocado_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 winteravocado_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 winterbrusselsprouts_mc.buttonMode = true;
 winterbrusselsprouts_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 winterbrusselsprouts_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 wintercabbage_mc.buttonMode = true;
 wintercabbage_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 wintercabbage_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 wintercauliflower_mc.buttonMode = true;
 wintercauliflower_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 wintercauliflower_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 winterceleryroots_mc.buttonMode = true;
 winterceleryroots_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 winterceleryroots_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 winterfennel_mc.buttonMode = true;
 winterfennel_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 winterfennel_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 wintergrapefruit_mc.buttonMode = true;
 wintergrapefruit_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 wintergrapefruit_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 wintermandarin_mc.buttonMode = true;
 wintermandarin_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 wintermandarin_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 wintermushrooms_mc.buttonMode = true;
 wintermushrooms_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 wintermushrooms_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 winterpears_mc.buttonMode = true;
 winterpears_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 winterpears_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 winterspinach_mc.buttonMode = true;
 winterspinach_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 winterspinach_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
 wintersquash_mc.buttonMode = true;
 wintersquash_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
 wintersquash_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);

 function pickupObject(event:MouseEvent):void
 {
event.target.startDrag(true);
event.target.parent.addChild(event.target);
objectoriginalX = event.target.x;
objectoriginalY = event.target.y;
response_txt.text = " ";
 }
 function dropObject(event:MouseEvent):void
 {
event.target.stopDrag();
var matchingTargetName:String = "target" + event.target.name;
var matchingTarget:DisplayObject = getChildByName(matchingTargetName);
if (event.target.dropTarget != null && event.target.dropTarget.parent == matchingTarget)
{
    event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
    event.target.removeEventListener(MouseEvent.MOUSE_UP, dropObject);
    event.target.buttonMode = false;
    event.target.x = matchingTarget.x;
    event.target.y = matchingTarget.y;
    response_txt.text = "You did it!";
    score++;
    scoreField.text = String(score);
}
else
{
    event.target.x = objectoriginalX;
    event.target.y = objectoriginalY;
    response_txt.text = "Try again";
}
 };

所以从我之前说过的话,如果你能看到灰色的盒子并且用他们指定的类型命名,那就是我之前提到的狗/猫盒子。而上面的图像是我正在谈论的那种


所以问题就像你在图片中看到的那样,菊苣蔬菜被放置在第二个盒子的秋天(它所属的地方),从我看到的代码参考,他们这样做。

OBJECT 这个项目只等于1 CONTAINER 这是一个方块

我一直在搜索将1张图像拖放到指定的组类型的方法,这将是正确的(即使你把它放在第一个盒子上,如果是第二个盒子,图像将自动进入第二个盒子小组是真的)

另外,我注意到我的计时器不工作,并且说明答案是真还是假的文本会产生错误或不完整的输出。如果你看到 ou i it 那就是我所指的你应该做的

感谢那些愿意回答的人。即时通讯仍然在寻找解决方案,但我似乎无法找到与我相同的问题

2 个答案:

答案 0 :(得分:0)

很难回答这个问题,因为你没有向我们展示任何代码,因此我会用我认为正确的概念来回答它。

如果我理解正确,你就会有一个概念层次,也就是说,首先是狗,然后是金毛猎犬和拉布拉多犬,对于猫来说也是如此。您需要以拉布拉多犬和金毛猎犬是狗的“儿子”的方式来组织您的代码或图形,这样就可以很容易地验证它们是否是狗。您可以使用层次结构(超级和子类),或者通过使拉布拉多盒子成为Dog盒子,也就是拉布拉多盒子的.parent指向Dog盒子。

如果您需要更好的答案,则必须详细说明您的问题,方法是向我们展示一些代码或.fla如何组织以及如何验证。

答案 1 :(得分:0)

行。

这是我认为你想要的:

让一个水果进入“秋季”组,但无论你把它放在什么灰盒子里面(在“秋天”里面),让特定的水果总是掉到盒子#2(顶行的第二个盒子)

以下是尝试这样做的方法(这些是代码snipets):

fallapple_mc.buttonMode = true;
fallapple_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
fallapple_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
fallapple_mc.droppedGroupName = "Fall"; //I can't use the fallapple_mc.name, since it's "fallapple_mc", not the group name that I want so I have to input the required value manually into this variable
fallapple_mc.droppedBoxIndex = 2; // here I manually input the correct box index for the group

既然已经设置了所需的数据,你必须稍微改变一下dropObject函数(以及其他一些事情,稍后会详细介绍):

function dropObject(event:MouseEvent):void
{
    event.target.stopDrag();
    //CHANGES BELLOW
    //var matchingTargetName:String = "target" + event.target.name;
    var matchingTargetName:String = "target" + event.target["droppedGroupName"]; //dynamic access to a variable (the []s) to stop the compiler from being annoying for you...
    var matchingTarget:DisplayObject = getChildByName(matchingTargetName);
    if (event.target.dropTarget != null && event.target.dropTarget.parent == matchingTarget)
    {
        event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
        event.target.removeEventListener(MouseEvent.MOUSE_UP, dropObject);
        event.target.buttonMode = false;
        //CHANGES BELLOW
        //event.target.x = matchingTarget.x;
        //event.target.y = matchingTarget.y;
        event.target.x = matchingTarget.getChildByName("box"+event.target["droppedBoxIndex"]).x; //Here getChild returned the *correct box* so i use it's x and y to position it (might be off a little)! 
        event.target.y = matchingTarget.getChildByName("box"+event.target["droppedBoxIndex"]).y; 
        response_txt.text = "You did it!";
        score++;
        scoreField.text = String(score);
     }
     else
     {
        event.target.x = objectoriginalX;
        event.target.y = objectoriginalY;
        response_txt.text = "Try again";
     }
 };

先决条件:

1)如果您未将 Fall组动画片段的实例名称更改为“targetFall”,则上述更改将失败

2)上面失败,如果内,(动画片段)实例名称 对他们。这些盒子需要有实例名称,如“box1”,“box2”,“box3”等,以便此代码能够正常运行。

这应该给你一些基本的东西开始玩...... 期待这个代码失败,我编程盲目,但它接近它应该看起来如此跟踪跟踪跟踪变量及其值或调试调试调试####,直到你让它工作......

如果您遇到困难,请随时在此回答的评论中要求澄清/帮助......