jeudi 26 novembre 2015

how to use .visible properties in as3?

I just want to make some objects visible="false". But I can't. I can make some objects invisible, however it is not working for the objects in the array. Here is my codes. When score=3, objects should be invisible. It is a catching game. I use Adobe Flash CC.

Can u help me?

package {
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.Timer;
    import flash.utils.getDefinitionByName;

    public class CatchingGame extends MovieClip {
        var catcher:Catcher;
        var nextObject:Timer;
        var objects:Array = new Array();
        var score:int = 0;
        const speed:Number = 7.0;

        public function CatchingGame() {
            catcher = new Catcher();
            catcher.y = 350;
            addChild(catcher);
            setNextObject();
            addEventListener(Event.ENTER_FRAME, moveObjects);
        }

        public function setNextObject() {
            nextObject = new Timer(1000+Math.random()*1000,1);
            nextObject.addEventListener(TimerEvent.TIMER_COMPLETE,newObject);
            nextObject.start();
        }

        public function newObject(e:Event) {
            var goodObjects:Array = ["Circle1","Circle1","Circle1"];
            var badObjects:Array = ["Square1","Square2", "Circle2"];
            if (Math.random() < .5) {
                var r:int = Math.floor(Math.random()*goodObjects.length);
                var classRef:Class = getDefinitionByName(goodObjects[r]) as Class;
                var newObject:MovieClip = new classRef(); 
                newObject.typestr = "good";
            } else {
                r = Math.floor(Math.random()*badObjects.length);
                classRef = getDefinitionByName(badObjects[r]) as Class;
                newObject = new classRef(); 
                newObject.typestr = "bad";
            }
            newObject.x = Math.random()*500;
            addChild(newObject);
            objects.push(newObject);
            setNextObject();
        }

        public function moveObjects(e:Event) {
            for(var i:int=objects.length-1;i>=0;i--) {
                objects[i].y += speed;
                if (objects[i].y > 400) {
                    removeChild(objects[i]);
                    objects.splice(i,1);
                }
                if (objects[i].hitTestObject(catcher)) {
                    if (objects[i].typestr == "good") {
                        score += 1;

                    } 
                    if (score < 0) score = 0;
                    scoreDisplay.text = "Score:" +score;
                    removeChild(objects[i]);
                    objects.splice(i,1);
                }

            }
            for(var k:int=objects.length-1;k>=0;k--){
            if (score == 3){finished.text="Well Done!";
                catcher.visible=false;
                scoreDisplay.visible=false;

                objects[k].visible=false;   }           


                }

            catcher.x = mouseX;

        }
    }
}

Aucun commentaire:

Enregistrer un commentaire