19 Replies Latest reply on Feb 26, 2009 8:28 AM by Ned Murphy

    using .onRelease but  converting

    chopTheWood Level 1
      I'm trying to get away from the on() handlers and use the preferred .onWhatever. The problem as illustrated in the folowing code is that I nee to convert a string to an object (I think). The string is the concatenated columnName+".mc"+clipNum; which will evaluate to something like: "_level0.clip2_mc.mc5" This is the correct target path but, when the mc is clicked on, it doesn't do what's inside the function.
      ...clues for the clueless? thanks
        • 1. Re: using .onRelease but  converting
          Ned Murphy Adobe Community Professional & MVP
          What are you trying to do?
          • 2. Re: using .onRelease but  converting
            chopTheWood Level 1
            I want to get the _y position of the "mc"+clipNum movieClip (a child of columnName) so I can slide a pointer in (vertically) next to it. This illustrates the thumb image that has been clicked on. There are 6 child mcs in a column, the column being the parent mc.

            I know it will work if I can just get the string (example: "_level0.clip2_mc.mc5") to work within the .onRelease
            • 3. using .onRelease but  converting
              Ned Murphy Adobe Community Professional & MVP
              That kind of string won't work as far as identifying/targeting an object. Something more of the form... = this[columnName]["mc"+clipNum]; would be more what you are after.

              What would originate calling the hiliteThumb function?

              I'm just getting a sense that you're taking a convoluted, and possibly dead end, path to do something that can probably be straightforward.

              Will the pointer also be inside with the buttons?
              • 4. Re: using .onRelease but need to converting
                Level 7
                >> thumbTarget.onRelease = function() {

                You have to use bracket notation when targeting a clip with strings.
                Something like so:

                this[columnName + ".mc" + clipNum].onRelease = function(){

                Dave -
                Adobe Community Expert

                • 5. Re: using .onRelease but  converting
                  chopTheWood Level 1
                  I tried it in both of the above suggested ways but it still isn't working.

                  this[columnName + ".mc" + clipNum].onRelease = function(){
                  // do this


                  this[columnName]["mc"+clipNum].onRelease = function(){;
                  // do this

                  neither works. The string I'm using does evaluate (as a string) to the proper target path: _level0.col1_mc.mc1. However it's not recognizing it in order to process the .onRelease = function (){

                  • 6. Re: using .onRelease but  converting
                    Ned Murphy Adobe Community Professional & MVP
                    I don't think the string is your issue. Both Dave and I have told you the correct way to get a string to be evaluated as an object.

                    I think the problem is in your approach to a solution.

                    What would originate calling the hiliteThumb function?

                    • 7. Re: using .onRelease but  converting
                      chopTheWood Level 1
                      Okay here's a sketch of how it works;

                      Somebody clicks on a thumbnail size image to bring up a large image. The thumb image is, let's say mc5. mc5 is one of 6 images in a vertically grouped array (not actually in an array just stacked vertically) of images called col1_mc. So, someone clicks on col1_mc.mc5 which loads the large image for this thumbnail.
                      (there are 10 columns in all, so 60 images)

                      I have a pointer that _y tweens up from the bottom of the screen and hovers next to the clicked thumb (pointing to its direct center in terms of its calculated _y position)

                      A "responsible" programmer would probably create all the mcs for the thumbs on the fly instead of making a 10 x 6 grid of them. But I don't care to get that abstract, I prefer to see that actual form of it when I'm working on the site. In other words , I'm more concrete.

                      Everything worked fine in the past, but I've been using on(press) inside each of the mcs instead of .onRelease. I was told to get with the program and use .onRelease instead of on(press). Made sense. So, in frame 1 of the _root movie I have the above script which isn't responding to the mouse clicks in the thumb mcs.

                      What I tried so far is to use the brackets [ ] in my code as you suggested above but that doesn't seem to be working. Nothing actually gets inside the function. I figured it had to be that I was using a string "col1_mc.mc5" when it needs to be an object.

                      If you go to http://www.cduboispaintings.com you can see an example of how it works. This site has only 4 vertical thumbs.

                      That's about it. I hope I am being clear at explaining this. Your assistance is appreciated.
                      thanks, Chop
                      • 8. Re: using .onRelease but  converting
                        chopTheWood Level 1
                        Well I think I figured it out. The .onRelease =function() only works with buttons, but my design has movieClips. Is there a way to accomplish the same thing with movieClips?
                        • 9. Re: using .onRelease but  converting
                          Ned Murphy Adobe Community Professional & MVP
                          So nothing is calling the hiliteThumb function?
                          • 10. Re: using .onRelease but  converting
                            chopTheWood Level 1
                            Well, yes I have that function included in the .onRelease(). I didn't include it in the script listing (I just put "do this") because that wasn't an issue. The issue was that the .onRelease() wasn't firing when someone clicks on the movie clip, so nothing was happening. I thought it might have been that the variable that I put before the .onRelease() wasn't the correct data type. But now I discover that this doesn't work with movie clips, just buttons. So now my question is: I can't load a .jpg image into a button, right? So how to I get the .onRelease to work with a movie clip release or press? Or should I just go back to putting the script into the mc itself, e.g. on(press) { }


                            • 11. using .onRelease but  converting
                              Ned Murphy Adobe Community Professional & MVP
                              It will also work for movieclips. To confirm this for yourself, create a movieclip with an instance name "mc" and put this code in the timeline:

                              mc.onRelease = function(){

                              Back to your function. I was wondering what the purpose could be for you creating an object in the function. Which really makes me wonder what the object is and what "// do this" involves. It may be because you thought that might be the way to use the string to target the object. If that's the case, revise the function as follows (I don't know if it will properly target it if you have that _level0 in the picture, but that can be resolved as well somehow):

                              • 12. Re: using .onRelease but  converting
                                chopTheWood Level 1
                                Okay, here's a super simplification of the issue. This script appears on the first frame. I took out the variables and put in literals. How can it go wrong? It still doesn't work. Also, I notice that the pointer does not change to a hand when hovering over the movie clip like it does if I use a button.

                                _level0.col1_mc.mc1.onRelease = function() {

                                _root.monitor2_txt.text = "this is inside the function";

                                • 13. Re: using .onRelease but  converting
                                  Ned Murphy Adobe Community Professional & MVP
                                  It can easily go wrong. I didn't say your problem would be solved by fixing the way you target the object, just showed you the way to do it. You are convinced your problem lies in that string, but I do not think it does. Unfortunately, that's the only part you want to focus on. You still haven't identified what calls that hiliteThumbs function. And I am really curious what you are trying to assign onRelease code to in that function.

                                  For the mouse over problem you can try setting the useHandCursor property to true, but by default it would be. If you create the simple example I offered, it should display the hand cursor. If your button/mc is not displaying it, and the function isn't working, your problem may be that you aren't assigning any button code to the movieclip... you may be off target.
                                  • 14. Re: using .onRelease but  converting
                                    chopTheWood Level 1
                                    If we just focus on the latest simple example (forget about the hilite stuff) then I' miffed about the fact that the text field monitor2_txt.text doesn't show "this is inside the function" It should if the .onRelease is firing. So I'm trying to simplify it by throwing out as much extraneous stuff as I can. I looked into the "helP' section for Flash and it gives a .onPress example for a mc and a .onRelease example for a button. I tried your example in another .fla and it did work. But it doesn't here and that's what I'm trying to figure out.

                                    My question, then, if there exists a parent/child mc such that we have:
                                    a .jpg is loaded into the child mc1
                                    shouldn't the script:
                                    _level0.col1_mc.mc1.onPress = function() {
                                    _root.monitor2_txt.text = "this is inside the function";
                                    (note I've now changed it to .onPress)
                                    I'm not using trace because it's on a server, trace doesn't work.

                                    I've tried it all of the ways suggested by you and Dave.
                                    BTW I do have these clips sitting behind a mask. Is this a problem when using .onPress? It works okay if I just put in the on(press){} into each mc
                                    It could be something stupid (usually is) that I'm doing.
                                    I appreciate all your help.
                                    • 15. Re: using .onRelease but  converting
                                      Ned Murphy Adobe Community Professional & MVP
                                      Where does col1_mc live relative to the main timeline (_root)?
                                      • 16. Re: using .onRelease but  converting
                                        chopTheWood Level 1
                                        It's on the _root timeline.

                                        Hey, I just tried this:
                                        Made a new.fla. I made a red square into an mc and called it mc1, I made a blue square into an mc and called it mc2, I inserted a new symbol (movie clip) and called it mc3. I highlighted all of them and made them into a mc called col1_mc (as the parent of all 3). So it's just the same as my other .fla except instead of all mcs having .jpgs in them, two of them are just graphics. The path, then for any of them is col1_mc.mc1 (.mc2 or .mc3).. just like the real thing.

                                        Now, here's the code I put into frame 1:

                                        var mcLoader:MovieClipLoader = new MovieClipLoader();
                                        _level0.col1_mc.mc3.onRelease = function() {
                                        trace("inside function");

                                        A .jpg gets loaded into mc3. But guess what?
                                        _level0.col1_mc.mc3.onRelease doesn't work BUT
                                        _level0.col1_mc.mc2.onRelease works
                                        _level0.col1_mc.mc1.onRelease works

                                        Maybe then, you can't have it work with a .jpg inside it?
                                        • 17. using .onRelease but  converting
                                          Ned Murphy Adobe Community Professional & MVP
                                          I'm providing a link here to a file that you might find helpful. It includes an fla and an image file so that you don't have to adjust anything to use it, just keep the two files in the same folder. It is saved as a Flash 8 file, so hopefully you can work with that.

                                          Sample: loadClip and onRelease
                                          • 18. Re: using .onRelease but  converting
                                            chopTheWood Level 1
                                            thanks, I can use that example. It's similar to the one I described above, the difference being that you haven't any mcs that are "blank" to begin with (as when created by the "insert/ new symbol/movieClip" . You are replacing an image w/ a loaded .jpg. I guess that's the rub, can't start off using a blank mc.

                                            Well, I appreciate the help. I know what mods I have to make for it to work. This was a long topic, time to close.
                                            thanks again,
                                            • 19. Re: using .onRelease but  converting
                                              Ned Murphy Adobe Community Professional & MVP
                                              You're welcome.

                                              You can start off with a blank mc, but you said you weren't creating things on the fly, being more "concrete", so I provided a concrete version.