13 Replies Latest reply on Sep 8, 2009 7:22 PM by Flanders_ZA-IgqhAi

    onLoadComplete  - baffled

    Flanders_ZA-IgqhAi

      Hi, I'm really stuck with this. Here's my AS2 code for onLoadComplete:

       

      function onLoadComplete(target){
            preloader_mc.gotoAndPlay(102);

            target._visible = true;

            target.play();
            preloader_mc.removeMovieClip();
      }

       

      My problem is this: I have an ending sequence for my preloader animation (preloader_mc). This sequence begins on frame 102 and I want the sequence to play out before the following occurs:

       

      target._visible = true;

      target.play();
      preloader_mc.removeMovieClip();

       

      I can't place this code on the last frame of my preloader because I can't seem to reference the target clip from there. I can remove the preloader clip with _parent.preloader_mc.removeMovieClip() but ultimately that doesn't help me.

       

      In my main timeline under function onLoadComplete(target), how do I tell it to play preloader_mc up 'til frame x before executing the above 3 lines of code?

       

      Any help would be much appreciated.

        • 1. Re: onLoadComplete  - baffled
          Ned Murphy Adobe Community Professional & MVP

          I don't know why you can't target target from the end of your 102 activity, but it may be as simple as using a combo..._parent reference (ex: _parent._parent.target._visible = true; ).  In any case, you could pull those last three lines of code into a separate function that you call from the end of that 102 timeline.  If you still face the same issue, you probably just need to apply a _parent reference to the function call.

           

          If you can describe how the target object exists wrt the reat of the show, maybe some help cam be offered for that.

          • 2. Re: onLoadComplete  - baffled
            Flanders_ZA-IgqhAi Level 1

            Hi Ned,

             

            As soon as I attempt _parent._parent.target._visible = true;, I get a problem whereby as soon as a '.' is placed in front of 'target', 'target' turns blue. In other words it appears to be seeing target as a button property or something.

             

            The target object is simply referring to the movie clip being loaded. I only want it visible and playing once preloader_mc has reached a certain frame.

            • 3. Re: onLoadComplete  - baffled
              Ned Murphy Adobe Community Professional & MVP

              target is probably not a good name to assign to an object... anytime you see code turn blue it means it's actionscript of some sort.  I know in AS3 it has definite usage, but I can't recall where target gets used in AS2.

               

              In any case, if you go with the second function for the last 3 lines approach, you should be able to manage that from a _parent point of view.  At the end of whatever goes on in the 102 timeline, have it call that function

              1 person found this helpful
              • 4. Re: onLoadComplete  - baffled
                Flanders_ZA-IgqhAi Level 1

                Hi Ned, sorry for the late comeback. It got well into the AM here by the time I gave up.

                 

                I tried assigning a different name to the object without any luck. (it worked properly within onLoadStart, on LoadProgress etc.) so I know that wasn't the issue.

                Within these events, the object is recognised but as soon as it is referenced outside (on my last frame of the 102 sequence), nothing happens even with _parent.

                 

                As I'm sure you can tell, I'm quite clueless here. I wonder if you could give an example of how I could create a function for the last three lines alone whilst recognising target?

                ie. when preloader_mc gets to frame x, execute these three lines of code.

                • 5. Re: onLoadComplete  - baffled
                  Ned Murphy Adobe Community Professional & MVP

                  Something along the lines of....

                   

                  // change your original function into two functions.

                   

                  function onLoadComplete(target){
                        preloader_mc.gotoAndPlay(102);

                  }

                   

                  function showTarget(){

                        target._visible = true;

                        target.play();
                        preloader_mc.removeMovieClip();
                  }

                   

                  // at the end of the preloader_mc timeline in frame x call:

                   

                  _parent.showTarget();

                  1 person found this helpful
                  • 6. Re: onLoadComplete  - baffled
                    Flanders_ZA-IgqhAi Level 1

                    Hi Ned,

                     

                    Thanks so much for your quick replies. What you've said there makes sense to me but I'm still not having any luck. Here's all my code for the preloader with your suggestion added:

                     

                    function onLoadStart(TheSection){

                         attachMovie("preloader anim", "preloader_mc", 500, {_x:350, _y:245});
                         preloader_mc.endingClip.stop();
                    }

                     

                    function onLoadProgress(TheSection, loadedBytes, totalBytes){
                         TheSection.stop();

                         TheSection._visible = false;
                         var StepUpBytes = totalBytes/100;
                         stepFrame = Math.floor(loadedBytes/StepUpBytes);
                         if(stepFrame<1){

                              stepFrame = 1;
                          }

                         preloader_mc.gotoAndStop(stepFrame+1); 
                    }

                     

                    function onLoadComplete(TheSection){
                         preloader_mc.gotoAndPlay(102);
                         trace("complete")
                    }

                    function showTarget(){
                         TheSection._visible = true;
                         TheSection.play();
                         preloader_mc.removeMovieClip();
                    }

                    function onLoadInit(TheSection){
                         trace("init")
                    }

                     

                    As you can see, within preloader_mc, there is another movie clip (endingClip) set to invisible from start and is visible and played from frame 102. On the last frame of endingClip, I have:

                     

                    stop();
                    _parent._parent._parent.showTarget();
                    trace("SHOW TARGET FUNCTION EXECUTES")

                     

                    The only way I get a returned trace on this is if I use _parent._parent._parent. yet neither TheSection shows up, nor does preloader_mc.removeMovieClip(); work.

                    Any suggestions?

                    • 7. Re: onLoadComplete  - baffled
                      Ned Murphy Adobe Community Professional & MVP

                      I was probably mistakenly believing that those three lines of code worked as you originally had them, just not when you wanted them to work.  Apparently they are not proerly targeting things, but I am not in a position to be able to tell where they are wrt that code being executed.  So you'll have to work out where they are relative to that code.

                       

                      By the way, if most of that code is on the main timeline, you can probably avoid the repeated _parent references and just use _root instead.  Using _root may also lead you to correctly targetoing for those three lines of code.

                      1 person found this helpful
                      • 8. Re: onLoadComplete  - baffled
                        Flanders_ZA-IgqhAi Level 1

                        Hi Ned,

                         

                        On my first attempt at implementing the showTarget function you pointed out, I used _root. but when doing so, the trace returned nothing. The only way I've been able to get a trace is by using the _parent._parent._parent.

                         

                        Here is an example of where TheSection is invoked by pressing a button. TheSection is loaded into a blank clip on the stage called DesignClip.

                         

                         

                        navMenu.navClip.Section4But.onPress = function  () {
                             startPreload("flash/Design.swf");
                             function startPreload(url){
                             loader_mcl.loadClip(url, DesignClip);

                        //...irrelevant

                        }

                         

                        All of the code above is indeed placed on frame1 of the main clip (except of course for the calling of the showTarget function).

                         

                        Edit: Oh, the 3 lines of code did work when placed inside onLoadComplete or onLoadInit. The problem was that they executed before the preloader_mc.endingClip had a chance to play out.

                        • 9. Re: onLoadComplete  - baffled
                          Ned Murphy Adobe Community Professional & MVP

                          If the code worked before when all four lines were together, then it should still work.  I have a feeling you just aren't targeting things properly.  With your new mention that TheSection lives inside DesignClip, that becomes more evident.  That would imply that you need to include DesignClip in your targeting path.  Your bringing up DesignClip enforces my earlier statement regarding my not being in a position to be able to determine how you need to target things.  If you think thru the parent/child relationships from the _root you should be able to target things properly.  I can only guess that with the newly identified mc in the picture, maybe your targeting has to be _root.DesignClip.TheSection.visible = false;  But that's just guessing on my part... you should have the full set of relationships in front of you.

                          1 person found this helpful
                          • 10. Re: onLoadComplete  - baffled
                            Flanders_ZA-IgqhAi Level 1

                            Hi Ned,

                             

                            I have established that _root.showTheSection(); was working from the last frame of endingClip.

                            The reason I was getting no traced return on it from within preloader_mc (I think) was because it was executing preloader_mc.removeMovieClip() before it had a chance to do so.

                             

                            As for TheSection not working - I'm still at a loss. It only seems to be affected from within function onLoadStart, function onLoadProgress, function onLoadComplete and function onLoadInit.

                             

                            These are all dependent/linked to on new MovieClipLoader() whereas function showTheSection(){ is not.

                             

                            There is nowhere that I have named any instance TheSection.

                            • 11. Re: onLoadComplete  - baffled
                              Ned Murphy Adobe Community Professional & MVP

                              There is nowhere that I have named any instance TheSection. ???  There should be if that's what your code is trying to target.

                              • 12. Re: onLoadComplete  - baffled
                                Flanders_ZA-IgqhAi Level 1

                                TheSection is only referenced in  - function onLoadStart(TheSection){, function onLoadProgress(TheSection), function onLoadComplete(TheSection) and onLoadInit(TheSection)

                                • 13. Re: onLoadComplete  - baffled
                                  Flanders_ZA-IgqhAi Level 1

                                  Hi Ned,

                                   

                                  After much mucking about I've finally figured it out.

                                   

                                  A simple

                                   

                                  trace(TheSection)

                                   

                                  was all that was needed. This reveals the the path of the trarget clip (in my case, (TheSection))

                                   

                                  It returned _level0.MyMystery_mc

                                   

                                  So, this is used when referencing the target clip anywhere outside of onLoadStart, onLoadProgress, onLoadCompleteon & onLoadInit

                                   

                                  Anyway, thanks a ton for your help. It came in very handy.

                                   

                                  This newb has learned something today. .