17 Replies Latest reply on Jul 18, 2006 7:40 PM by swim4it

    Possible to pass a 'case' value?

    swim4it
      Is it possible to pass a 'case' value from one layer to another?

      One of my buttons on level 300 is trying to pass a 'case' value to level 100. Here is the code on the button:

      pizza.vbut.onRelease = function() {
      _level100.pizza_slice=2;
      tellTarget("_level100");
      }

      Is this correct?

      Then, level100 is trying to retrieve it by this code:

      switch (pizza_slice) {
      case 1 :
      title.pageTitle.htmlText = "Logos";
      myMCL.loadClip("images/logo1.jpg", this.thumb1);
      myMCL.loadClip("images/logo2.jpg", this.thumb2);
      myMCL.loadClip("images/logo3.jpg", this.thumb3);
      myMCL.loadClip("images/logo4.jpg", this.thumb4);
      break;
      case 2 :
      title.pageTitle.htmlText = "Advertisements";
      myMCL.loadClip("images/ad1.jpg", this.thumb1);
      myMCL.loadClip("images/ad22.jpg", this.thumb2);
      myMCL.loadClip("images/ad3.jpg", this.thumb3);
      myMCL.loadClip("images/ad4.jpg", this.thumb4);

      break;
      }


      Am I missing something in this code? I know it's not passing the variable because when I add the line:
      "pizza_slice=2;"
      above the switch statement it works fine.
        • 1. Re: Possible to pass a 'case' value?
          blemmo Level 1
          This is possible, but the switch code has to be executed after the assignment. It looks like it's on a frame, so it will only execute when the player enters this frame; if you change the pizza_slice var afterwards, it will have no effect as long as the player frame doesn't enter that frame again.
          You could put the switch code into a function, and execute this when the button is pressed:
          --
          function switchAndLoad(){
          switch (pizza_slice) {
          case 1 :
          title.pageTitle.htmlText = "Logos";
          myMCL.loadClip("images/logo1.jpg", this.thumb1);
          myMCL.loadClip("images/logo2.jpg", this.thumb2);
          myMCL.loadClip("images/logo3.jpg", this.thumb3);
          myMCL.loadClip("images/logo4.jpg", this.thumb4);
          break;
          case 2 :
          title.pageTitle.htmlText = "Advertisements";
          myMCL.loadClip("images/ad1.jpg", this.thumb1);
          myMCL.loadClip("images/ad22.jpg", this.thumb2);
          myMCL.loadClip("images/ad3.jpg", this.thumb3);
          myMCL.loadClip("images/ad4.jpg", this.thumb4);

          break;
          }
          }
          --
          Then your button code can call this function:
          --
          pizza.vbut.onRelease = function() {
          _level100.pizza_slice=2;
          _level100.switchAndLoad();
          }
          --
          There's no need to use tellTarget, it's outdated, use the dot syntax instead like you did in the line before.

          hth,
          blemmo
          • 2. Possible to pass a 'case' value?
            swim4it Level 1
            Ok - so I replaced this:

            _level100.pizza_slice=2;
            tellTarget("_level100");

            with this:

            _level100.pizza_slice=2;

            then on level 100 I put the switch function switchAndLoad() - or rather just made the code I had into that function - on frame 6 (there is no stop action on any frame prior to that) . Then, because that function doesn't even exist until frame 6 on level 100 call the switchAndLoad() function after it is defined within that same frame (6).

            The function works if I define the pizza_slice value on that frame testing it like this:
            pizza_slice=2;
            switchAndLoad()

            but when I comment out "pizza_slice=2;" it doesn't seem to find a value....from layer 300

            Antyhing else I'm missing? I can slap up the fla files if that would help.


            • 3. Re: Possible to pass a 'case' value?
              blemmo Level 1
              You have to call the function from level 300. The code in level 100 executes only when the player arrives at the frame, so when it stops there, you can change pizza_slice as you want, it won't execute again as long as you don't make it so. That's why the function is added, you can call that anytime. Put
              _level100.switchAndLoad();
              in your button code to make it execute when the button is clicked.
              To see if it's executing, you can put this line at the beginning of the function:
              trace("switchAndLoad called");
              This will show that line in the output window whenever the code executes.

              cheers,
              blemmo
              • 4. Re: Possible to pass a 'case' value?
                swim4it Level 1
                Do I have to call the function in level 300 even though the function actually resides in 100? I didn't think I could change dynamic text until the dynamic text box is actually on the frame the function it is called (which is on frame 6 in level 100).
                • 5. Re: Possible to pass a 'case' value?
                  blemmo Level 1
                  Yes, you have to call it to make it execute. The location doesn't matter as long as you specify the path to it. That goes for all objects and functions, so you could have your textfield in another frame or level, as long as it is present when the function executes and the path to it is right.
                  I assume the movie stops in frame 6 in your setup. When the function is defined there (it could also have been defined in frame 1) and the textbox exists on stage in that frame, you can call the function from anywhere in your movie with the _level100 prefix.
                  • 6. Re: Possible to pass a 'case' value?
                    swim4it Level 1
                    Right - so theoretically if the function is defined in level 300 - I can actually call it in frame 6 of level 100 (if level 300 has already loaded) and it should pick up the variables right?
                    • 7. Re: Possible to pass a 'case' value?
                      blemmo Level 1
                      Right, this should work. But there's a possible trap here, because the code in level 300 executes after the code in lower levels, I think. So the function in level 300 should be defined before frame 6 when you want to call it in that frame from level 100. The other way round it would be ok, the function gets defined in the code of frame 6 of level 100 and can be called in the same frame from level 300.
                      So to be on the safe side, define the function in an early frame, maybe frame 1, then you can call it later without problems.

                      greets,
                      blemmo
                      • 8. Re: Possible to pass a 'case' value?
                        swim4it Level 1
                        OK. I've uploaded the root level, level 100, and level 300 that I'm working with:

                        http://www.midnight007.com/pizza/layer_root.fla
                        http://www.midnight007.com/pizza/layer_300.fla
                        http://www.midnight007.com/pizza/layer_100slices.fla

                        With what I am doing now, the root layer loads first, then layer 300 - which is the menu. Specifically I'm dealing with the buttons on the pizza (the pepperoni slice right now). The code is in the pizza movieclip on the pepperoni button. (Yes...I know there's an easier way to do the buttons than putting the code here, but I haven't gotten the other movie to work yet - so currently the code is there...)

                        Anyway, when the pepperoni slice button is clicked at the end of the onRelease function I put "_level100.pizza_slice=2;" which should define the pizza_slice variable for my switch statement. Then, when it's clicked another switch statement of "page=4" is defined along with the "gotoAndPlay" frame 14 of the root level. The playhead will play frames 14 - 28 on the timeline and stp at 28 - where the switch statement calls the variable of "page" and executes the script to pull up level 100 with layer_100slices.swf.

                        Then, once level 100 is pulled up - within frame 6 is where the switch statement for pizza_slice is defined and called after the definations. I can't call the statement until frame 6 because the dynamic text fields aren't there until frame 6.

                        So - I still don't understand why it isn't working.

                        It works if I definate pizza_slice within frame 6 - as I tested it. So it looks like the variable of pizza_slice from level 300 is not being passed.

                        • 9. Re: Possible to pass a 'case' value?
                          blemmo Level 1
                          Sorry, but I'm quite lost here. I had a look at the .flas you provided, but couldn't find an MC with 28 frames as you described. If you use _root in level 300, it will resolve to the root clip of level 300, not the root clip in the player. You can get to the 'real' root with the _level0 prefix.
                          But back to your pizza_slice var: the button in the level 300 clip is actually 2 buttons, one instance from frame 1-9, another one from frame 11-17. In frame 10 it's just a bitmap. Now these 2 instances have slightly different codes on them, which confused me a lot until I got behind that. I think in the first run, the code from frames 1-9 is used, after that only frames 11-17, is that right? So take care that the scripts are identical.
                          Now if the script on the button includes this:

                          _level100.pizza_slice=2;
                          trace("_level100.pizza_slice = "+_level100.pizza_slice);
                          _level100.switchAndLoad();

                          and in level 100, the switchAndLoad function starts with this:

                          trace("switchAndLoad called: pizza_slice = "+pizza_slice);

                          the output is this:
                          switchAndLoad called: pizza_slice = undefined
                          _level100.pizza_slice = 2
                          switchAndLoad called: pizza_slice = 2
                          switchAndLoad called: pizza_slice = undefined

                          So the var passing works, but it seems that the level 100 movie gets replayed or the switchAndLoad gets called again with an undefined pizza_slice. This is just the case for the first click, the following clicks just output
                          _level100.pizza_slice = 2
                          switchAndLoad called: pizza_slice = 2
                          so it's all fine there. I couldn't figure out the difference between the first and the following clicks, but I guess you know, so you should try to find and avoid the 2nd 'undefined' call.

                          greets,
                          blemmo
                          • 10. Re: Possible to pass a 'case' value?
                            swim4it Level 1
                            Ok the Movie Clip you asked about that had 28 frames is actually layer_300 - not a movie clip but a movie. And yes, I realized the frames 1-9 button instance has a different code than 11-17 - I was working primarily with 1-9 then I was planning on changing 11-17 once I got it worked out.

                            Alright, I changed the script on the button to include:
                            _level100.pizza_slice=2;
                            trace("_level100.pizza_slice = "+_level100.pizza_slice);
                            _level100.switchAndLoad();

                            Then I added this to frame 6 on level 100:
                            trace("switchAndLoad called: pizza_slice = "+pizza_slice);

                            I removed the switchAndLoad(); at the end of the actions in frame 6 so it's not called once again. And it is coming up with _level100.pizza_slice = 2 in the trace, however, it's not reading it properly because if it were, the title would change and say 'Advertisements'.

                            For this, don't you have to wait until frame 6 over level 300 to load to actually call the function with _level100.switchAndLoad(); - because if it's called in level 300 and frame 6 hasn't loaded - the default of 'Logos' will show up in the title.

                            I've re-uploaded the new fla files:

                            http://www.midnight007.com/pizza/layer_root.fla
                            http://www.midnight007.com/pizza/layer_300.fla
                            http://www.midnight007.com/pizza/layer_100slices.fla

                            • 11. Re: Possible to pass a 'case' value?
                              blemmo Level 1
                              Ok... it's still confusing to me, but it's getting clearer. When the movie starts, the level 100 MC isn't loaded. You can set the pizza_slice var, but there's no switchAndLoad() to execute. The MC gets loaded when level 300 comes to frame 28, but then the pizza_slice gets deleted.
                              I think you should change your setup. The switch function and the pizza_slice var could be in level 0, so they will always be present. The function definition can go in frame 1, so it's always available. Then change the path in the level 300 code to _level0.pizza_slice and _level0.switchAndLoad().
                              You could also pass the value directly to the function, if this is the only time pizza_slice is used, so you don't need it as an extra var. Then it would be enough to say _level0.switchAndLoad(2), and in the function, use the parameter:
                              --
                              function switchAndLoad(selection:Number){

                              trace("switchAndLoad called: selection = "+selection);

                              switch (selection) {
                              case 1 :
                              ...
                              --

                              Now I'm hungry.

                              greets,
                              blemmo
                              • 12. Re: Possible to pass a 'case' value?
                                swim4it Level 1
                                Won't this still cause a problem with the function being called (in layer 300) prior to the dynamic text links loading in level100 in frame 6?
                                • 13. Re: Possible to pass a 'case' value?
                                  blemmo Level 1
                                  That's a good point. What I don't understand: it seems as if the level 100 movie always gets unloaded when you click one of the slices, and then another movie gets loaded into level 100. So there's no use setting the var and the title text in level 100 with the click, because it will unload the movie right after that. Is that right?
                                  I guess it's better then to have the variable in level 0, and read it from level 100 when the movie loads (again). That's basically how you started, except that pizza_slice would be on level 0. Then you wouldn't need that switchAndLoad function, but could go with that simple switch statement in frame 6 in level 100. Just set _level0.pizza_slice in the button code, and let the movie unload and reload by the code in the frames of level 300. When the new level 100 movie plays, it switches _level0.pizza_slice in frame 6 and sets the title and pictures. That way the pizza_slice var would still be present after the reload of level 100.
                                  Hope this does it... I really want some pizza now. :)
                                  • 14. Re: Possible to pass a 'case' value?
                                    swim4it Level 1
                                    So, I'm not sure I understand correctly. When you say have the variable in level 0 - do you mean have the switch statement in level 0 too? Or just set the variable to level0 through the button action scripting of _level0.pizza_slice? If all I need to do is to set the variable target to level0 - then is there any action scripting changes needed on level0 - or will it store it without changing anything?
                                    • 15. Re: Possible to pass a 'case' value?
                                      blemmo Level 1
                                      It's just the pizza_slice var in level 0, so it won't get deleted by the loading movie in level 100. The switch statement may stay in its frame in level 100 and use the var from level 0 >> switch(_level0.pizza_slice).
                                      So, you just need to change the target path for the var. There's no code needed in level 0, as long as you don't need a default value (the pizza_slice var will only exist after the first click on a slice).
                                      • 17. Re: Possible to pass a 'case' value?
                                        swim4it Level 1
                                        Ok I finally got it to work. THANK YOU SO MUCh!!!