A Flash Developer Resource Site

Page 1 of 3 123 LastLast
Results 1 to 20 of 51

Thread: strange Shuffler

  1. #1
    Senior Member
    Join Date
    Jan 2003
    Location
    Middel east
    Posts
    239

    strange Shuffler

    hi all I have alot of array which i want to Shuffle and diplay on a text i tried a Shuffler a took form this forum but no did not work
    Attached Files Attached Files

  2. #2
    See-n-reMember azwaldo's Avatar
    Join Date
    Mar 2003
    Location
    Sonoran Desert
    Posts
    745
    howdy alhurayas,
    not completely sure what you are having trouble with...the sort fxn appears to work;
    if the problem is that you want to display the entire list of terms (the whole array), then where you have this in the AS of the btns:
    Code:
    //_root.framtext.dynamicTxt = (myLetters25[i]);
    and
    _root.framtext.dynamicTxt = (myLetters24[i]);
    try this:
    Code:
    _root.framtext.dynamicTxt = (myLetters25);
    and
    _root.framtext.dynamicTxt = (myLetters24);
    Maybe you could describe what you want to happen at each btn click...
    Also, do you intend to have blank spaces after the array elements 'yes' and 'zero'?
    Last edited by azwaldo; 01-27-2005 at 06:05 PM.
    __azwaldo__

  3. #3
    Senior Member
    Join Date
    Jan 2003
    Location
    Middel east
    Posts
    239

    thank you very much

    the idea is read game for kids where in text display a word ( arrayA words starting with the letter a ......arrayz words starting with the letter z)
    then the array have been all words call ( read ) i wnat the button to be disable preventing the same words to start again
    when i used your code all the words of the array displayed on the text i juist want word by word until the end of the array .
    ps there another problem which i will tell you about but for now letts solve this one thankkkkkss for your replay

  4. #4
    See-n-reMember azwaldo's Avatar
    Join Date
    Mar 2003
    Location
    Sonoran Desert
    Posts
    745
    Okay, now i understand. Here are some things to consider:

    First: You have used a single variable (i) as a counter for both buttons. If you click nutton2 twice and then click nutton1, you will get the third element of the Z array - even though you have only clicked nutton1 once. Rather, you want to have each button increment its own variable. You could use "i" with the particular letter (such as ia, ib, ic,... iz). It is best to declare such variables on the main timeline (in the actions layer, frame 1) so they are accessible by all scripts throughout the movie. Then you will just need refer to each variable using the path
    Code:
    _root.myLetters25[i]
    Second: There is another way to 'pull' the words from the array that might work better for you: You can use the Array.shift method to remove the first element of an array. (Look at this page for more about Array.shift) In this way, you would not need to track 26 variables. You could just check the array after each shift, and disable the button if the array is empty

    Third: Will you eventually have 26 buttons? Consider using a loop to create/name/place each of the 26 buttons. That is how the buttons are created for this demo

    Also: Where you have _root.nutton2.enabled = false; you can just use this.enabled = false;
    __azwaldo__

  5. #5
    Senior Member
    Join Date
    Jan 2003
    Location
    Middel east
    Posts
    239

    thank but

    thank you alot i tried it this was but did not word
    code:

    on (press) {
    //checks to see if i isn't higher than the length of the array

    if (ia<myLetters25.length) {

    _root.framtext.dynamicTxt = (myLetters25[ia]);
    trace(myLetters25[ia]);
    //increments i
    ia++;
    //else, if i is the same as the length of the array, perform an action:
    } else {
    _root.nutton2.enabled = false;
    _root.nutton2._alpha = 20;
    trace("end 2");
    }
    }


    but did not work another thing is the use of this.enabled = false; did not work now iam using flash mx2004
    it worked in mx
    thank again you are a great help

  6. #6
    Senior Member
    Join Date
    Jan 2003
    Location
    Middel east
    Posts
    239

    also used shift

    i also used what you Recommended the shift did not use
    code:
     
    on (press) {
    shifted = myPets.shift();
    if (myPets.length<0) {
    trace(myPets);
    } else {
    /// this.enabled = false;
    _root.nutton2.enabled = false;
    _root.nutton2._alpha = 20;
    }
    }
    on a frame
    myPets = ["cat", "dog", "bird", "fish"];


    but also did not work thanks for any help
    i also noticed that it will always take out one which will make one word undiplayed unread
    Last edited by alhurayas; 01-28-2005 at 07:55 AM.

  7. #7
    Inspector General
    Join Date
    May 2001
    Posts
    493
    hello fellas,
    i was going to sit back and let azwaldo do all the dirty work on this one, but was too intrigued by the concept to let it go.
    also it seems we are all in significantly different time zones so i thought i could help speed things up.

    alhurayas, i like your game concept and commend you on your flash and english skills. keep at it.

    it seems the biggest problem with your original file was that (as azwaldo noted) you were using the same counter variable "i" for determining the position in multiple arrays.

    the first thing i did was initiate counter variables for each myLetters array:

    code:

    // c is for counter, the number is for which myLetters array it is for.
    c23 = 0;
    c24 = 0;
    c25 = 0;



    once i added this, both buttons went through the arrays as planned and disabled the buttons if their were no items left in the array.

    Next, I figured that since you are going to have 26 buttons, it would be a real shame if you wanted to change your on(press) behavior and have to edit all 26 buttons.

    being that each array has a number in its name and that same number is now being used as a counter variable for that array, i figured each button could have a number (counter) that tells a function which array to access and which array counter variable to update.

    code:

    //this function is on the main timeline
    //each button has its own counter# that it sends to this function on(press)
    button_press = function (counter) {
    //set a variable that holds the name of the array to be referenced

    arrayname = "myLetters"+counter;
    //set a variable that holds the name of the counting variable we will increment
    countervar = "c"+counter;
    trace(newline+"***")
    trace("arrayname= "+arrayname+newline+"countervar= "+countervar+newline+countervar+"= "+_root[countervar]);
    //if our countervar is less than the arrays length than do things
    if (_root[countervar]<_root[arrayname].length) {
    _root.framtext.dynamicTxt = _root[arrayname][_root[countervar]];
    trace(_root[arrayname][_root[countervar]]);
    _root[countervar]++;
    } else {
    //i also gave your buttons appropriate names like button23, button24, button25
    _root["button"+counter].enabled = false;
    _root["button"+counter]._alpha = 20;
    trace("end 2");
    }
    };

    //each button now has a script like this:
    on (press) {
    button_press(24);
    }




    give it a look here:
    http://www.doyouhaveapen.com/posting...ding_game.html

    also as azwaldo noted, you could use a loop to place all the buttons on the stage, at the same time you could initiate your counter variables and button actions. if you need help let us know.


    mx2004 attached if you need mx, let me know (i found that saving as mx puts my super long functions on one line which is annoying).

    also I put in a few traces that will better illustrate what is going on.
    Last edited by meglomor; 01-28-2005 at 11:46 AM.

  8. #8
    Inspector General
    Join Date
    May 2001
    Posts
    493
    oops attachment here
    Attached Files Attached Files

  9. #9
    See-n-reMember azwaldo's Avatar
    Join Date
    Mar 2003
    Location
    Sonoran Desert
    Posts
    745
    are ready to roll alhurayas?

    this is an interesting project. many techniques that have not been mentioned yet can be used - several concepts that will probably be new to you, but stay with it and you will probably learn a lot. and, now that meglomor has joined the thread this is really a graduate-level flash lesson...
    __azwaldo__

  10. #10
    Senior Member
    Join Date
    Jan 2003
    Location
    Middel east
    Posts
    239

    thanks is not enough

    like to thank azwaldo for the help ( you too meglomor)
    it is what i want exactly
    if i will try to complete me game now thanks again

  11. #11
    See-n-reMember azwaldo's Avatar
    Join Date
    Mar 2003
    Location
    Sonoran Desert
    Posts
    745
    glad to hear it, alhurayas. FK rocks!
    ...and please post it here when you have a working version...
    __azwaldo__

  12. #12
    Inspector General
    Join Date
    May 2001
    Posts
    493
    nice work men.

  13. #13
    Senior Member
    Join Date
    Jan 2003
    Location
    Middel east
    Posts
    239

    here you are but with a bug

    azwaldo here you are but there is a bug in it plays the last element of an array twice why
    how to play
    all of the player in the game use the keyboard while the teacher have control over the game using the mouse
    play1 use the letter a ( it first )
    play2 use the letter 5
    play3 use the letter h
    play4 use the letter n
    thank you simple ha

  14. #14
    Senior Member
    Join Date
    Jan 2003
    Location
    Middel east
    Posts
    239

    here you are but with a bug

    azwaldo here you are but there is a bug in it plays the last element of an array twice why
    how to play
    all of the player in the game use the keyboard while the teacher have control over the game using the mouse
    play1 use the letter a ( it first )
    play2 use the letter 5
    play3 use the letter h
    play4 use the letter n
    thank you simple ha
    tried to attach it but too large 328k
    there is the swf
    Last edited by alhurayas; 07-12-2009 at 05:29 PM.

  15. #15
    See-n-reMember azwaldo's Avatar
    Join Date
    Mar 2003
    Location
    Sonoran Desert
    Posts
    745

    Gadzooks!

    Wow! Nice job in the design, al. And the interaction is very clean, too. I am impressed.
    The bug might be in how you are looping or handling the counter variable... for example, there is a difference between using this:

    counter++;

    ...and using this:

    ++counter;

    Check this page for more about it.

    Since the file is large, can you just post the ActionScript for the buttons and the fxns? Also, I did not understand what you are saying with this:
    play1 use the letter a ( it first )
    play2 use the letter 5
    play3 use the letter h
    play4 use the letter n
    __azwaldo__

  16. #16
    Senior Member
    Join Date
    Jan 2003
    Location
    Middel east
    Posts
    239

    i will try to fix it

    thank for all your help i willtry to fix it , about
    play1 use the letter a ( it first )
    play2 use the letter 5
    play3 use the letter h
    play4 use the letter n
    spelling hit first 4 players who it the keyboard first get the chance to answer ( read) the letter are a for player1, n for player2 5 for player3 and h for player4
    thankssssssss

  17. #17
    See-n-reMember azwaldo's Avatar
    Join Date
    Mar 2003
    Location
    Sonoran Desert
    Posts
    745

    post the code?

    "...spelling hit first 4 players who it the keyboard first..."
    Still not understanding this completely - the "spelling hit" (this is done by different players? do four people sit at the monitor with a finger on a different key?)

    if you get stuck with the counter/frameNumber bit, maybe you can just post the code for the fxn you are working on (if the file is too big to attach)
    __azwaldo__

  18. #18
    Senior Member
    Join Date
    Jan 2003
    Location
    Middel east
    Posts
    239
    same mistake
    i made the same mistake again (it for hit)
    try to play it choose a letter the word will be display try to player 4 players useing the keyboard
    ( hit first ,his letter first)
    play1 use the letter a
    play2 use the letter 5
    play3 use the letter h
    play4 use the letter n hope i made myself clear
    back to the code i tried
    _root[countervar]++;
    it this way
    _root[++countervar]; one word each time
    and i tried it this way
    _root++[countervar];
    err
    there is the complete code thank you
    Attached Files Attached Files

  19. #19
    See-n-reMember azwaldo's Avatar
    Join Date
    Mar 2003
    Location
    Sonoran Desert
    Posts
    745
    _root[countervar]++; should work, if not, the problem may be elsewhere in your code...do you use the trace command to check (debug) your scripts? you can check out this tute for more on errors and debugging

    have opened the text file you attached, but it is difficult to study AS code in that format* - but, i may have found one problem: you have used the same word ("counter") for a function name that you use elsewhere for a variable...try renaming the fxn
    it is also helpful to use descriptive verbs for function names,
    like function countClicks()


    *I am also wondering why the file is so large at this point: are you using a lot of images? large sound files? maybe you could create a dummy copy of the fla ("Save as" with different name) and remove large sound files and images, then you could attach the fla here
    Last edited by azwaldo; 01-30-2005 at 12:24 PM.
    __azwaldo__

  20. #20
    Senior Member
    Join Date
    Jan 2003
    Location
    Middel east
    Posts
    239

    thank again

    thank you will i try again and agian to fix it
    but still i think i need you help
    this game is main your work and other flash pro ( from actionscrpit.org ) who helped me with button listern code
    give me a day ... for trying .
    thaaaaaaaaanks


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center