将值隐式强制转换为不相关类型flash.display:DisplayObject

时间:2015-11-07 03:18:30

标签: actionscript-3 flash actionscript adobe

我在ActionScript 3中使用Adobe Flash cs6。

在我的代码中,我收到一个错误: error

这是我的布局,标有实例名称。 layout

错误我不太明白,但是,这是我的代码: 另外:推1-3和拉1-3是.PNGS在图书馆!!

import flash.events.MouseEvent;
import flash.system.fscommand;
import flash.media.Sound;

var DRAGGY:DragObject = new DragObject();
var stageObjects:Array = new Array();
var Correct:Sound = new sndCorrect();
var Incorrect:Sound = new sndIncorrect();

createNewDraggy();

nextItem.visible = false;
prevItem.visible = false;
itemBox.text = "Cart";


//map: item-frameName
var items:Object = new Object();
items.push1 = "push1";
items.push2 = "push2";
items.push3 = "push3";
items.pull1 = "pull1";
items.pull2 = "pull2";
items.pull3 = "pull3";

var push1Pos:Boolean = false;
var push2Pos:Boolean = false;
var push3Pos:Boolean = false;
var pull1Pos:Boolean = false;
var pull2Pos:Boolean = false;
var pull3Pos:Boolean = false;


var arrayIndex:int = 0;
var unsortedItems:Array = new Array("push1","push2","push3","pull1","pull2","pull3");

var tempPosX:int = 0;
var tempPosY:int = 0;



//nextItem.addEventListener(MouseEvent.CLICK, nextObject);
//prevItem.addEventListener(MouseEvent.CLICK, previousObject);

function createNewDraggy()
{
    DRAGGY = new DragObject();
    DRAGGY.stop();
    DRAGGY.x = 439;
    DRAGGY.y = 234;
    stage.addChild(DRAGGY);
    stageObjects.push(DRAGGY);

    DRAGGY.addEventListener(MouseEvent.MOUSE_DOWN, startItemDrag);
    DRAGGY.addEventListener(MouseEvent.MOUSE_UP, stopItemDrag);

}


/*function nextObject(evt:MouseEvent):void
{
    if (unsortedItems.length > 0)
    {
        if (arrayIndex < unsortedItems.length - 1)
        {

            if (unsortedItems[arrayIndex + 1] != null)
            {
                arrayIndex++;
                changeItem(arrayIndex);
                //trace(arrayIndex);
            }
            else
            {
                for (var i:Number=0; i<=6; i++)
                {
                    if (unsortedItems[i] != null)
                    {
                        break;
                        arrayIndex = i;
                        //trace("loop" + arrayIndex);

                    }
                }
            }
            //trace("array index:" + arrayIndex);
        }
    }
}*/

function previousObject(evt:MouseEvent):void
{
    if (arrayIndex > 0)
    {
        arrayIndex--;
        changeItem(arrayIndex);
    }
}

function changeItem(index:int)
{
    //trace("valueof:" + items.propertyIsEnumerable(unsortedItems[index]));
    //trace("index object:" + unsortedItems[index]);
    //trace("test: " + items[unsortedItems[index]]);
    if (unsortedItems.length > 0)
    {
        DRAGGY.gotoAndStop(items[unsortedItems[arrayIndex]]);
        setText();
    }
}

function startItemDrag(evt:MouseEvent):void
{
    evt.target.startDrag();
    tempPosX = evt.target.x;
    tempPosY = evt.target.y;
}

function stopItemDrag(evt: MouseEvent):void
{
    evt.target.stopDrag();
    switch (DRAGGY.currentLabel)
    {
        case "push1" :

            if (DRAGGY.hitTestObject(g2_non))
            {
                DRAGGY.x = 734;
                DRAGGY.y = -114;
                createNewDraggy();
                //trace("item to remove: " + items[unsortedItems[arrayIndex]]);
                unsortedItems.splice(arrayIndex, 1);
                push1Pos = true;
                checkPos();
                changeItem(arrayIndex);
                Correct.play();


            }
            else
            {
                evt.target.x = tempPosX;
                evt.target.y = tempPosY;
                Incorrect.play();

            }
            break;

        case "push2" :

            if (DRAGGY.hitTestObject(g2_mix))
            {
                DRAGGY.x = -55;
                DRAGGY.y = -95;
                createNewDraggy();
                //trace("item to remove: " + items[unsortedItems[arrayIndex]]);
                //trace("item to remove: " + DRAGGY.currentLabel);
                unsortedItems.splice(arrayIndex, 1);
                push2Pos = true;
                checkPos();
                changeItem(arrayIndex);
                Correct.play();

            }
            else
            {
                evt.target.x = tempPosX;
                evt.target.y = tempPosY;
                Incorrect.play();

            }
            break;

        case "push3" :

            if (DRAGGY.hitTestObject(g2_non))
            {
                DRAGGY.x = 900;
                DRAGGY.y = 18;
                createNewDraggy();
                //trace("item to remove: " + items[unsortedItems[arrayIndex]]);
                unsortedItems.splice(arrayIndex, 1);
                push3Pos = true;
                checkPos();
                changeItem(arrayIndex);
                Correct.play();

            }
            else
            {
                evt.target.x = tempPosX;
                evt.target.y = tempPosY;
                Incorrect.play();
            }
            break;

        case "pull1" :

            if (DRAGGY.hitTestObject(g2_non))
            {
                DRAGGY.x = 740;
                DRAGGY.y = 115;
                createNewDraggy();
                //trace("item to remove: " + items[unsortedItems[arrayIndex]]);
                unsortedItems.splice(arrayIndex, 1);
                pull1Pos = true;
                checkPos();
                changeItem(arrayIndex);
                Correct.play();

            }
            else
            {
                evt.target.x = tempPosX;
                evt.target.y = tempPosY;
                Incorrect.play();
            }
            break;

        case "pull2" :

            if (DRAGGY.hitTestObject(g2_mix))
            {
                DRAGGY.x = 125;
                DRAGGY.y = 5;
                createNewDraggy();
                //trace("item to remove: " + items[unsortedItems[arrayIndex]]);
                unsortedItems.splice(arrayIndex, 1);
                pull2Pos = true;
                checkPos();
                changeItem(arrayIndex );
                Correct.play();

            }
            else
            {
                evt.target.x = tempPosX;
                evt.target.y = tempPosY;
                Incorrect.play();
            }
            break;

        case "pull3" :

            if (DRAGGY.hitTestObject(g2_mix))
            {
                DRAGGY.x = -33;
                DRAGGY.y = 122;
                createNewDraggy();
                //trace("item to remove: " + items[unsortedItems[arrayIndex]]);
                unsortedItems.splice(arrayIndex, 1);
                pull3Pos = true;
                checkPos();
                changeItem(arrayIndex);
                Correct.play();


            }
            else
            {
                evt.target.x = tempPosX;
                evt.target.y = tempPosY;
                Incorrect.play();
            }
            break;

    }
}

var startIndex:int = 0;

function checkPos()
{
    if (push1Pos == true && push2Pos == true && push3Pos == true && pull1Pos == true && pull2Pos == true && pull3Pos == true)
    {
        for (var obj:int = 0; obj < stageObjects.length; obj++)
        {
            stage.removeChild(stageObjects[obj]);
            gotoAndStop(1, "Finish");

        }

    }
}

function setText()
{
    switch (DRAGGY.currentLabel)
    {
        case "push1" :
            itemBox.text = "Cart";
            break;

        case "push2" :
            itemBox.text = "Kick Soccer Ball";
            break;


        case "push3" :
            itemBox.text = "Push Swing";
            break;


        case "pull1" :
            itemBox.text = "Cart";
            break;


        case "pull2" :
            itemBox.text = "Drag Desk";
            break;


        case "pull3" :
            itemBox.text = "Drag Donkey";
            break;


    }
}

我认为错误与坐标/位置有关。 有人能帮我找到这个小错误吗? 十分感谢大家! 另外:推1-3和拉1-3是.PNGS在图书馆!!

PS:读取,转到第51帧以获取错误。

0 个答案:

没有答案