Skip to main content
Inspiring
December 1, 2011
Answered

Event.currentTarget.visible = false back to true

  • December 1, 2011
  • 1 reply
  • 1218 views

Hi, I've got a tricky issue, I' m making a game involving learning activities. In this one, I've got to push letters on a screen and compose a word. Each time you click on a letter it sets its state to false, so you can't click it again. Everything as worked so far, but right now I don't know how to set back to visible the letters I clicked on.

Basically I've to do this, for instance, if you make a mistake selecting the letters you want for composing the word. I managed to create a delete button you can press, so the letter will be pop out from the textField, but how can I set the button/letter back to visible ?

I tried to push the clickedLetters into an Array, but then they become Strings so visible = true won't work. Any help ?

Thanks

private function takeTheLetter(Event:MouseEvent):void

        {

            var letterTraced:String = Event.currentTarget.letter.text.charAt(0);

            clickedLettersArray.push(letterTraced);

            //show the letters that are typed;

            var composeWord:String = clickedLettersArray.toString();

            composeWord = composeWord.split(",").join("");

            hero_txt.text = composeWord;

            //remove the pressed letter

            Event.currentTarget.visible = false;

            currentTargetArray.push(letterTraced);

            trace(currentTargetArray);

        }

private function deleteTheLetter(Event:MouseEvent):void

        {

            clickedLettersArray.pop();

            //set the array back to a string;

            var correctedWord:String = clickedLettersArray.join(",");

            //set the true sprite to compare

            correctedWord = correctedWord.split(",").join("");

            hero_txt.text = correctedWord;

        }

This topic has been closed for replies.
Correct answer Mistakenness

sorry I was in a hurry writing... It works now, I've just to let them visible once a time, maybe I have just to target the last item in the array

Thanks to the help.


private function deleteTheLetter(evt:MouseEvent):void

        {

            clickedLettersArray.pop();

            //set the array back to a string;

            var correctedWord:String = clickedLettersArray.join(",");

            //set the true sprite to compare

            correctedWord = correctedWord.split(",").join("");

            hero_txt.text = correctedWord;

            currentTargetArray[currentTargetArray.length-1].visible = true;

            currentTargetArray.pop();

        }

THIS IS THE CORRECT CODE, IF SOMEONE NEEDS IT.

1 reply

Ned Murphy
Legend
December 1, 2011

What yoiu should do is store the object in your array instead of the letter that is buried within it. 

Also, you should not be using "Event" (with the capital E) the way you are since that is a class name.  It is actually used as a variable where you have it so keep it lower case and you can name it pretty mch anything you want... event, evt, e, george, etc...

Inspiring
December 1, 2011

I also tried to push in the array the object, but if I set the visible property back to true nothing happened. I think that it doesn't know what to set back to true.

private function deleteTheLetter(Event:MouseEvent):void

        {

            clickedLettersArray.pop();

            //set the array back to a string;

            var correctedWord:String = clickedLettersArray.join(",");

            //set the true sprite to compare

            correctedWord = correctedWord.split(",").join("");

            hero_txt.text = correctedWord;

            for each(var btn in currentTargetArray)

            {

                button.visible == true; //don't works

                // do something

                trace("works")

            }   

        }

In this way I get a trace for each Objects I have set visible == false.

private function randomizePosition():void

        {

            letterContainer.y = 200;

            for each (var buttonClip in stringToLettersArray)

            {

                if (button.x > stage.stageWidth - 90)

                {

                    button.x = Math.floor(Math.random() + 20);

                    button.y +=  button.height + 10 * Math.random();

                }

                button.x +=  button.width + Math.random() * Math.random() + 15;

            }

        }

this function set the Object on the stage

Ned Murphy
Legend
December 1, 2011

           for each(var btn in currentTargetArray) 

            {

                button.visible == true; //don't works

1) button is not btn

2) == is for testing equality,  = is for assigning value.

3) as already mentioned, change "Event" to "evt" or something else