如何加载活动/非活动按钮

时间:2014-01-13 16:09:56

标签: actionscript-3

我创建一个包含5个元素的列。当您从列中单击一次元素时,即使关闭fla并再次加载它也无法再次单击它。只有单击了(要单击的当前元素)上的元素时,才能单击下面的元素。 / p>

所以我之前问过这样的问题,并且ppl告诉我将逻辑分成两个函数 - 如果它是你创建列的第一个FLA加载( createColumn() ),1,如果你的第二个第三个等等加载FLA你加载列( loadColumn())。 所以我这样做但现在我在解决加载 loadColumn()的逻辑时遇到了问题。我不知道的是:

我如何只将元素直接放在最后一个单击的元素下面,使其处于活动状态,其余部分处于非活动状态,直到单击此元素为止。这样的事情

第一次加载fla - >我创建了列并单击了第一个和第二个元素,然后我关闭了fla。

第二次加载fla->我看到元素1和2是不可点击的(假设我是第一次购买它们),元素3是可点击的,如果我点击(购买)元素3,元素4将是可点击的所以我只点击元素3并再次关闭fla。

第3次加载fla->现在我看到元素1,2和3 nonClickable,只有元素4可以点击。所以我点击它然后5激活到所以我也点击它。

最后加载fla->现在我看到所有元素都是不可点击的。 enter image description here

到目前为止,我只有淡化之前点击的按钮的逻辑,但我没有逻辑可以使下一个按钮可以点击。

我有两个类:Main()

import flash.display.MovieClip;
import flash.display.Sprite;
import flash.net.SharedObject;
import flash.events.MouseEvent;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;

public class Main extends MovieClip
{
    private var savedData:SharedObject = SharedObject.getLocal("Line_37");
    private var buttonThatHaveBeenClicked_Arr:Array = [];

    private var myButtons_Arr:Array = [];
    private var row:int = 5;

    public function Main()
    {
        if (savedData.data.myClickedButtons_Arr == undefined)
        {
            createColumn();
        }
        if (savedData.data.myClickedButtons_Arr != undefined)
        {
            loadColumn();
        }

    }

    private function createColumn():void
    {
        trace("                               1st time loading this game\n");
        var lastRowElement:BitmapButton = null;

        for (var i:int = 0; i < row; i++)
        {
            var bmpd:BitmapData = new BitmapData(60,60,false,Math.floor((0xff + Math.random() * 0xffffff)));
            var myImage:Bitmap = new Bitmap(bmpd);
            var myImage_mc:BitmapButton = new BitmapButton  ;
            myImage_mc.addChild(myImage);

            myImage_mc.x = 250;
            myImage_mc.y = 0 + i *( myImage_mc.height + 10);
            myImage_mc.name = "myImage_mc" + i;
            this.addChild(myImage_mc);

            myImage_mc.mouseChildren = false;
            myImage_mc.mouseEnabled = false;
            myImage_mc.addEventListener(MouseEvent.CLICK,onClick);

            if ((lastRowElement == null))
            {
                myImage_mc.mouseEnabled = true;
                myImage_mc.buttonMode = true;
            }
            else
            {
                lastRowElement.next_1 = myImage_mc;
            }
            lastRowElement = myImage_mc;
        }
    }

    private function loadColumn():void
    {
        trace("                               Game was played before\n");

        buttonThatHaveBeenClicked_Arr = savedData.data.myClickedButtons_Arr;
        trace("names of clicked buttons: " + buttonThatHaveBeenClicked_Arr + "\n");
        var number_ofSavedObjects:int = savedData.data.myClickedButtons_Arr.length;

        //-----
        for (var i:int = 0; i < row; i++)
        {
            var bmpd:BitmapData = new BitmapData(60,60,false,Math.floor((0xff + Math.random() * 0xffffff)));
            var myImage:Bitmap = new Bitmap(bmpd);
            var myImage_mc:BitmapButton = new BitmapButton  ;
            myImage_mc.addChild(myImage);

            myImage_mc.x = 250;
            myImage_mc.y = 0 + i * (myImage_mc.height + 10);
            myImage_mc.name = "myImage_mc" + i;
            this.addChild(myImage_mc);

            myImage_mc.mouseChildren = false;
            myImage_mc.mouseEnabled = false;
            myImage_mc.addEventListener(MouseEvent.CLICK,onClick);

            for (var h:int = 0; h < number_ofSavedObjects; h++)
            {
                var nameOf_lastSavedObject:String = savedData.data.myClickedButtons_Arr[h];

                if (myImage_mc.name == nameOf_lastSavedObject)
                {
                    trace("match: button " + myImage_mc.name + " will have 0.1 alpha");
                    myImage_mc.alpha = 0.1;
                }
            }
        }
    }

    private function onClick(ev:MouseEvent):void
    {
        var nameOfCell:String = ev.target.name;

        if (ev.target is BitmapButton)
        {
            var btn:BitmapButton = ev.currentTarget as BitmapButton;
            ev.currentTarget.alpha = 0.1;

            if (btn.next_1 != null)
            {
                btn.next_1.mouseEnabled = true;
                btn.next_1.buttonMode = true;
            }
            btn.buttonMode = false;
            btn.removeEventListener(MouseEvent.CLICK,onClick);

            buttonThatHaveBeenClicked_Arr.push(nameOfCell);
            savedData.data.myClickedButtons_Arr = buttonThatHaveBeenClicked_Arr;
            savedData.flush();
            savedData.close();
        }
    }
}

BitmapButton()

import flash.display.Sprite;

public class BitmapButton extends Sprite
{
    public var next_1:BitmapButton = null;
}

我只是想说我自己也试着解决它。我确实尝试了一个布尔值,当活动单元格的按钮名称是nextCell名称时,它会发生变化。 像if.name == nextToClickCell.name.Al也尝试制作Arrays,其中我将所有未触及的另一个和所有触摸的元素放在一起。也尝试将另一个数据保存到sharedObject并使用该数据来比较现在将激活的元素。然而......我无法做到 PS:sharedObj名称的“Line_37”是我在这个文件上试过的次数,不幸的是,这是我的第三个不同的文件名,具有相同的问题

1 个答案:

答案 0 :(得分:1)

加载以前的数据

这是您修改后的loadColumn()

private function loadColumn():void {
    createColumn();
    trace("                               Game was played before\n");

    buttonThatHaveBeenClicked_Arr = savedData.data.myClickedButtons_Arr;
    trace("names of clicked buttons:" + buttonThatHaveBeenClicked_Arr + "\n");

    var btn;
    for each (var btnName:String in buttonThatHaveBeenClicked_Arr) {
        trace("Disabling " + btnName);
        btn = this.getChildByName(btnName);
        btn.mouseChildren = false;
        btn.mouseEnabled = false;
        btn.alpha = 0.1;
    }

    var btnIndex:int = btnName.split("myImage_mc")[1]
    if (btnIndex + 1 < row) {
        btn = this.getChildByName("myImage_mc" + (btnIndex + 1));
        btn.mouseChildren = true;
        btn.mouseEnabled = true;
        btn.alpha = 1;
    }
}