Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

The sequential order of clicking movie clips fails to work in the second and further game rounds

New Here ,
Mar 17, 2014 Mar 17, 2014

Hello all.

Game Scenario:

I am making a simple "Alphabet Click" game. Alphabet movieclips are aligned in Grid form. When the player clicks on the "Start" button,

the alphabets get shuffled (grid-shuffling), and a Count Down Timer is triggered. Before the timer hits zero, the player is supposed to

click the alphabets in the correct alphabetical order. If the correct alphabet is clicked, its alpha gets changed. Once the "alpha" of

all the alphabets gets changed, the "start" button reappears, and the player should be able to play the next round (repeat the game).

Problem Situation:

The first round works fine. But, in the second round, the sequential order of clicking the alphabet-movieclips cannot be met.

Eg., the "alpha" of letterB is supposed to change, only when the player has already clicked letterA. And the "alpha" of

letterC is supposed to change only when the player has already clicked "letterA" and "letterB" in the correct order.

But, in my case, in the second round, even if the player straightaway clicks letterG, or letterR, its alpha changes.

Code:

In order to minimize the number of lines of code, i have created a smaller scenario of just nine-numbers (instead of letters)

placed in grid form.

//v1 to v9 are the instance names of other movieclips that i have created, to make the conditional statement function properly.

//ie., if movieclip n1 is clicked, then, movieclip v1 (whose alpha is already zero and hence hidden, becomes invisible. v1.visible = false;

//if(v1.visible == false){n2.addEventListener.....as shown in the code below}

var vis:Array = new Array(v1, v2, v3, v4, v5, v6, v7, v8, v9);

vis.forEach(visAttrib);

function visAttrib(v:* , index:int, array:Array){

v.alpha = 0;

}

startBtn.addEventListener(MouseEvent.CLICK, trigGame)

function trigGame(e:MouseEvent):void{

startBtn.visible = false;

//SEQUENTIAL CLICKING CODE:OPEN

this.addEventListener(Event.ENTER_FRAME, trial);

function trial(e:Event):void{

n1.addEventListener(MouseEvent.MOUSE_DOWN, alph1);

function alph1(e:MouseEvent):void

{n1.alpha = .7; v1.visible = false; n1.removeEventListener(MouseEvent.MOUSE_DOWN, alph1);}

if(v1.visible == false){n2.addEventListener(MouseEvent.MOUSE_DOWN, alph2);

function alph2(e:MouseEvent):void

{n2.alpha = .7; v2.visible = false; n2.removeEventListener(MouseEvent.MOUSE_DOWN, alph2);}

}

if(v2.visible == false){n3.addEventListener(MouseEvent.MOUSE_DOWN, alph3);

function alph3(e:MouseEvent):void

{n3.alpha = .7; v3.visible = false; n3.removeEventListener(MouseEvent.MOUSE_DOWN, alph3);}

}

//....the code continues from above in the same pattern till it reaches the code below

if(v8.visible == false){n9.addEventListener(MouseEvent.MOUSE_DOWN, alph9);

function alph9(e:MouseEvent):void

{n9.alpha = .7; v9.visible = false; n9.removeEventListener(MouseEvent.MOUSE_DOWN, alph9);

startBtn.visible = true;

var vis:Array = new Array(v1, v2, v3, v4, v5, v6, v7, v8, v9);

vis.forEach(visAttrib);

function visAttrib(v:* , index:int, array:Array){

v.visible = true;

}

var num:Array = new Array(n1, n2, n3, n4, n5, n6, n7, n8, n9);

num.forEach(numAttrib);

function numAttrib(nums:* , index:int, array:Array){nums.alpha = 1;

                                                                 }

                                             }

                              }

          }

//SEQUENTIAL CLICKING CODE:CLOSE

}

Can anyone please try to help me out

thanks in advance

with best regards

shamse tabriz

TOPICS
ActionScript
636
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2014 Mar 17, 2014

what are the 'n' objects?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 17, 2014 Mar 17, 2014

Sir,

the n objects are the movieclips..they are number-movieclips arranged in grid form...nine of them are there:

n1 to n9....they are arranged as a 3 by 3 grid so that when the player clicks the start button they get shuffled.

My actual game is based on alphabets from A to Z and an additional 4 movieclips so that it forms a total of 30 movieclips

arranged as 6 by 5 grid form.

Hope my explanation is clear

thanks again

with regards

shamse tabriz

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2014 Mar 17, 2014

then what are the v1,...,v9?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 17, 2014 Mar 17, 2014

Your code is exceedingly hard to read, because it's nonstandard and it also is poorly indented. Let me suggest a few things:

  1. Define your vis Array at the top level of this code, and don't keep redefining it in your functions.
  2. Your code looks like timeline code. If it's Class code, please use the conventions of Class code so that's easy to see. If it's Timeline code, say it's timeline code and what is on stage.
  3. Any function that you're adding as an event listener, define at the top level of your code as well. In other words, your function that is being added as an event listener should not be inside any other function.
  4. Let's not use forEach on the Array. Kudos for attempting functional programming, but it looks to me like you're having a hard time with just "ordinary" programming. Break that out into a for loop, and not only will it be easier for you to see and debug, but it will be more accessible to many of the regulars on this forum.
  5. Indent properly.

Once you've made your code more legible, post it and let's see what we have. Here are some general suggestions you may want to think about while you're refactoring your code that may help you to just solve the problem without having to come back.

  1. You can reference the object that triggered an event listener and remove that event listener without knowing which specific object triggered it. For example:
    DisplayObject(e.currentTarget).alpha=someNumber;
    EventDispatcher(e.currentTarget).removeEventListener(e.type, someFunction);
    This means you don't have to have 8,000 different versions of the same function so you can have one for each object. Instead, you can have one function for each thing that you need to do that is applied to multiple objects.
  2. You don't need to constantly be checking everything in every frame. The only time the state of your game can change is when one of your buttons is clicked. Only one button can be correctly clicked at any given moment. When a correct button is clicked, change its visual state and remove the correct listener from it and replace it with an incorrect listener, then move the correct listener to the object that's allowed to be clicked. This will simplify your logic considerably. You'll have two things to do--correct and incorrect--and these will never happen in response to the same event.

Good luck!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 18, 2014 Mar 18, 2014
LATEST

Hello kglad and Amy Balnkenship

i really appreciate your willingness to help me trobleshoot my problem....after reading both of yours replies, or response, i thought i had presented my problem-situation in a highly convoluted manner....i struggled a lot and came up with a more simple working method to my problem-situation and it seems to work well in simple situations...but when the situation gets more complicated i fails to work.

i have presented my new  problem situation under a new question entitled:

Too many eventListeners in nested form causes falsh cs6 debugging session to crash ?

if you can kindly guide me on this new situation your help will be most appreciated

with much thanks

shams

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines