A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: Find All Possibility with As

  1. #1
    Member
    Join Date
    Nov 2009
    Posts
    43

    Unhappy Find All Possibility with As

    Hello everybody. I just hope, that somebody can help me.
    I need to do a bit involved program for works automatically.
    So the program do the next:

    I have 6 buttons and a 4 and 9 litre barrels.
    With buttons you can do the next:
    A - Fill the second barrel.
    B - Fill the first.
    C - Empty second.
    D - Empty first.
    E - Decant from second to first, as many as it possible.
    F - Decant from first to second, as many as it possible.

    And the task is, to find the shortest way for the next:
    1 - In the end I have 1 litre in one of the barrels.
    2 - In the end I have 3 litres in one of the barrels.
    3 - In the end I have 6 litres in one of the barrels.
    4 - In the end I have 2 litres in one of the barrels.
    5 - In the end I have 7 litres in one of the barrels.

    I find all them with only my simply logic. But I need to make my programme, to find them automatically. It needs to find the shortest way for the solutions, and need to list the pressed buttons as you will see in the swf.
    (The solutions: A E D E / B F B F B F / A E D E D E A E / A E D E D E A E D E / B F B F B F C F B F)

    I need to do a permutation like cycle. I wrote the simply permutation, but it doesn't help, because the choices are repeatable.
    I think I need to do somehow a permutation with repeatable characters, and when it finds criterion than jump on the next, and it stops when one of the litre marker match with the number that you wrote in the input text field, near the button, that start the cycle. But I don't know how to start a script like this.

    Here is the swf and source for it>
    Swf in Html
    Source Fla


    Thanks forward your answer, tips or suggestions.
    Last edited by Creephun; 11-21-2009 at 09:26 AM.

  2. #2
    Cancerbero
    Join Date
    Jan 2003
    Location
    Mexico City.
    Posts
    26

    Red face

    I saw your fla.

    I guess I have it working, if I understood what you wish it to perform.

    But first, tell me if I've not stolen in vain sever hours to my pillow.

    When you write e.g. the number 6 and press the red upper button, do you want to see the application solve by it-self the task? If that's what you want, I can tell you that it works right now.

    Please tell me if I'm right for I start explaining you what to do, step by step and the reasons for each step.

    Now I'll get to sleep.
    One idea. One emotion. One project.

  3. #3
    Member
    Join Date
    Nov 2009
    Posts
    43
    Now, I want to works like this>
    First you write in a number into dynamic text(be) near that red button. Then you press it. The program starts calculating, orders for the buttons ( A B C D E F). And when one of the barrels' litre mark match with the number that you wrote in, the program write down the 'pressed' buttons in their right order. So yes, I want that you said. For example if you write in: 6 and press red button.
    With tracing or in dynamic text box, you get this: A E D E D E A E.

  4. #4
    Cancerbero
    Join Date
    Jan 2003
    Location
    Mexico City.
    Posts
    26

    Wink

    Well, I guess you are asking the compiler to make an artificial intellingence task, that it's not able to do. In other words, you want it to think for you. And I'm daring to say: "You want it to do your programming work".

    There for so, you have to give the program a break and provide it the procedures to do in each case.

    Said more concretely, you have to do your red upper button:

    If be is equal to 6, follow the way 6.
    If be is equal to 3, follow the way 3.
    Etc.

    Explain what you have done.


    ====

    1. Because you'll have to perform several times the six tasks your six buttons do, first you have to pass the six actions from your six blue buttons to the first (and only) frame and transform them to functions. The six blue buttons will only call the functions when they're pressed.

    Press the first frame and, after the existing code, adapt the content of each button, like this:

    Code:
    // For the A button:
    functionA = function () {
    	a = 0; //By the way, you could erase this line.
    	a = 9-liter2;
    	_root.liter2 = _root.liter2+a;
    	_root.eredmeny = _root.eredmeny + "A, ";
    }
    In the A button:

    Code:
    on (press) {
        functionA();
    }

    And so on for each button, but changing letter A with B, C, etc. Don't forget to pass and adapt the other five codes to the first frame.

    This way you'll be able to make each task everywhere you are in your program and not only when you press blue buttons.


    ====

    2. In the first frame, add the steps to follow for each case, by providing an array for each one of them. For 1 liter case:

    myArray = ["A", "E", "D", "E"];

    But this is not enough. You have to make possible a choice for each selected number. And insert them in a function that starts in a second moment:

    Code:
    determineArray = function () {
    	if (be == 1) {
    		myArray = ["A", "E", "D", "E"];
    	} else if (be == 3) {
    		myArray = [""]; //INSERT YOUR ANSWERS.
    	} else if (be == 6) {
    		; // etc.
    	}
    }
    3. In the red upper button, write the order to unleash the actions corresponding to the "be" imput text value.

    The code:

    on(press) {
    determineArray();
    }

    should be enough, but we have tow problems:

    First, human eye can't see what happens and only can see the goal. So, we have to make some kind of delay in order to watch comfortably all the steps. So, we'll build a "slower" named turningMC (or whatever).

    Second, in the be textfield, there may be values those not correspond to our five desired possibilities (1, 3, 6, 2, 7). So we have to restrict the begining of the tasks to our five possibilities.

    Then, the code in your red upper button will show like this:

    Code:
    on(press) {
    	// If "be" is a number between 1 and 3, or between 6 and 7.
    	if (!isNaN(be) && be > 0 && be < 4 || be > 5 && be < 8) {
    	// Do the next:
    		reset(); // (I'll explain reset() latter)
    		determineArray();
    		turningMC.play();
    	}
    }
    4. Now, we have to make a new movie clip. Press Cntrl + F8 keys. In the window that appears, type the name turningMC and press OK button.

    Now we are inside the new MC that will make slower the steps of each task. Select the only frame and type in the actions panel the next code:

    Code:
    stop();
    turn = 0;
    Add sever empty frames (7, 15 or 20) and at the end add a key frame where you'll type the next code:

    Code:
    if (turn < _root.myArray.length) {
    	if (_root.myArray[turn] == "A") {
    		_root.functionA();
    	} else if (_root.myArray[turn] == "B") {
    		_root.functionB();
    	} else if (_root.myArray[turn] == "C") {
    		_root.functionC();
    	} else if (_root.myArray[turn] == "D") {
    		_root.functionD();
    	} else if (_root.myArray[turn] == "E") {
    		_root.functionE();
    	} else if (_root.myArray[turn] == "F") {
    		_root.functionF();
    	}
        turn++;
        gotoAndPlay(2);
    } else {
        gotoAndStop(1);
    }
    Here you are making the compiler to do each task. As turn is equal to 0, the compiler makes the step 1 of the array that provides the answer. Then the compiler increases the turn value in 1 and restarts from the frame 2 until all the procedure is done (gotoAndStop(1)).

    Get out of the turningMC movie clip and in the stage drag and drop an instance of the turningMC movie clip. PLEASE, GIVE IT THE INSTANCE NAME: "turningMC".

    5. To clean the stage each time you press the red upper button, add the next code in the frame of the main time line, NOT in the turrningMC movie clip:

    Code:
    reset = function () {
    	eredmeny = "";
    	liter1 = 0;
    	liter2 = 0;
    }
    It's quite your current code in your other red "reset" button.

    You just have to replace that code in your red "reset" button with the next:

    Code:
    on(press){
    	reset();
    }
    6. The only thing you have to do is to add a dynamic text field and give it a variable name (e.g. dynamicTextField). In each function type:

    At the end of function A:

    Code:
    	dynamicTextField = dynamicTextField + "Button A pressed.\r";
    And at the reset function:

    Code:
    	dynamicTextField = "";
    Et voila!

    Tell me if it works.
    Last edited by cancerbero; 11-22-2009 at 02:26 PM.
    One idea. One emotion. One project.

  5. #5
    Cancerbero
    Join Date
    Jan 2003
    Location
    Mexico City.
    Posts
    26

    Cool

    Ah, don't forget (as I did) to make your last dynamic text field multiline and give it a good height.

    If you wish your demonstration to be slower, increase the number of empty frames in your turningMC movie clip. If you want that to be faster, erase some empty frames there.

    It would be nice that you make possible to solve the 4, 5, 8, and 9 cases. If you decide to do it, you'll have to erase the "&& < 0", etc. in the if line in the red upper button.

    Tell me what happens.
    One idea. One emotion. One project.

  6. #6
    Member
    Join Date
    Nov 2009
    Posts
    43
    Ohh many thanks.
    You saved my life.
    My teacher gave me this task, for better grade. My class is work in Delphi and Pascal(me too), but I better like flash, so I got it in this.

  7. #7
    Cancerbero
    Join Date
    Jan 2003
    Location
    Mexico City.
    Posts
    26

    Cool

    Ok. I'm glad my contribution made something.

    But tell me. Does it work? Is there anything you need for your project?

    Because I have some things to tell you to make your work a little bit easier.
    One idea. One emotion. One project.

  8. #8
    Member
    Join Date
    Nov 2009
    Posts
    43
    Yess, it's works fine thanks much
    Uhh, and I don't want to be ungrateful, but I talked with him. And he said, he wants to originally the programme solve out the orders by itself.
    I mean, that the program writer doesn't know about the "A E D E" and other orders.
    I know it's a bit too hard to make, so I just thought I write it to you, and maybe, if you have a bit time to think about it, or just some suggestions.
    Maybe I can write the program, if you just simply write me a task series in english.

    And of course, it would be great, if you can tell me those things, I'm always happy, if I can learn new things.
    With that you made for me, I learned using the arrays correctly, across on an example that I know what that do.
    And I learned how to delay a flash actionscript. It's not hard, but I never thought about this way

  9. #9
    Cancerbero
    Join Date
    Jan 2003
    Location
    Mexico City.
    Posts
    26

    Thumbs up

    Hi again.

    I'm not sure if flash can solve those problems by it-self. But give me some time to think about it.

    About my way to delaying a task, I did it because I don't know how to use the setInterval function. Well, the trap works.

    What I was to tell you is about the height of your containers water (on.clipEvent inside your MC).

    I would rather name the pair of MCs on your stage (smallContainer, bigContainer). Inside each one of them, I would name the water MCs (water). And I'd communicate the height property of each water MC from the first frame of your main time line, each time a function gets to work: smallContainer.water._height = . . . bigContainer.water._height = . . . .

    Well, your code works fine. I just send you an other idea.

    I think you could add a text with the instructions for users to know what's about your application.

    It would be a great contribution if you share here your final fla file. But don´t feel I'm pushing you.
    One idea. One emotion. One project.

  10. #10
    Member
    Join Date
    Nov 2009
    Posts
    43
    Okay I'll share it tomorrow, because, I need to rewrote those texts from my language onto english again But today I haven't too much time to do it.

  11. #11
    Cancerbero
    Join Date
    Jan 2003
    Location
    Mexico City.
    Posts
    26
    Bonne chance!
    One idea. One emotion. One project.

  12. #12
    Member
    Join Date
    Nov 2009
    Posts
    43

  13. #13
    Cancerbero
    Join Date
    Jan 2003
    Location
    Mexico City.
    Posts
    26
    COOL!!

    See you.
    One idea. One emotion. One project.

  14. #14
    Cancerbero
    Join Date
    Jan 2003
    Location
    Mexico City.
    Posts
    26
    Ah, two little details:

    1. In your instructions text, you wrote the word "than". I think it's "then".

    2. When Internet users type in a text field, they have the choice to type "Enter" key instead of pushing a button with the mouse cursor. So, I modified the first line in your upper red button, and added one line.

    This way, you only have to press one number and key and the "enter" key in each turn.

    Code:
    on(press, keyPress "<Enter>") {
    		reset();
    		determineArray();
    		turningMC.play();
    		Selection.setFocus("be");
    }
    Hope this helps.
    One idea. One emotion. One project.

  15. #15
    Member
    Join Date
    Nov 2009
    Posts
    43
    okay thanks Sorry my English isn't too good. :/

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