3 Replies Latest reply on Jul 3, 2007 7:37 AM by Newsgroup_User

    Unwanted rotation

    Phyrexian Level 1
      Hi there,


      I'm working on a little flash project again. Everything's working fine for now but I encountered this little problem. And don't understand why this problems happens. Please read...


      My site contains two swfs that are loaded in a 'container' swf.
      • images.swf are those big background images (animated fadein/fadeout)
      • main.swf is the actual site (menu, text, content)
      • tmp.swf is the container in wich the aforementioned swfs are loaded.


      The flash files are getting centered via actionscript (off-center images are intended that way). Everything works perfectly.
      Check it out here: [url]http://www.bodysong.co.uk/tmp/tmp.html[/url]

      Then I'd like to have them background images as big as the stage.
      I add one line of code and then it happens!!!! The background images are getting rotated!! I didn't add ANY rotation code at all and still this happens. Why?
      Check this wrong version here: [url]http://www.bodysong.co.uk/tmp_wrong/tmp.html[/url]

      Do you people understand why?



      This is the AS (in tmp.swf):
      [as]
      this.createEmptyMovieClip("images", this.getNextHighestDepth());
      this.createEmptyMovieClip("container", this.getNextHighestDepth());
      container.loadMovie("main.swf");
      images.loadMovie("images.swf");


      // center of the very first position of the swfs
      this.onEnterFrame = function() {
      container._x = Stage.width/2-472.5; // half the size of the main.swf is subtracted for perfect centering.
      container._y = Stage.height/2-287.5; //
      images._x = Stage.width/2.75; // divided to be off-center
      images._y = Stage.height/2.75;
      // images._height = Stage.height;
      // the line of code above is getting me in trouble. Adding this makes the background images rotate!!!!!??????
      };




      // stage listener for continuously recentering on stageResize

      var stageL:Object = new Object();

      stageL.onResize = function() {
      container._x = Stage.width/2-472.5;
      container._y = Stage.height/2-287.5;
      images._x = Stage.width/2.75;
      images._y = Stage.height/2.75;
      images._height = Stage.height;
      // the line of code above is getting me in trouble. Adding this makes the background images rotate!!!!!??????

      };

      Stage.addListener(stageL);


      [/as]
        • 1. Re: Unwanted rotation
          Level 7
          Phyrexian,

          > The flash files are getting centered via actionscript (off-center
          > images are intended that way). Everything works perfectly
          > Check it out here: [url]http://www.bodysong.co.uk/tmp/tmp.html[/url]

          I'm with ya. Looks good so far.

          > Then I'd like to have them background images as big as the
          > stage. I add one line of code and then it happens!!!! The
          > background images are getting rotated!! I didn't add ANY
          > rotation code at all and still this happens.

          Are we talking rotated (turned)? Or flipped? It's possible to flip
          images by setting their dimensions to the negative of what they were
          originally, even without any rotation applied.

          > Why?
          > Check this wrong version here:
          > [url]http://www.bodysong.co.uk/tmp_wrong/tmp.html[/url]

          Ah, that's a 90 rotation. Okay, well ... yes, that's interesting.

          > this.createEmptyMovieClip("images", this.getNextHighestDepth());
          > this.createEmptyMovieClip("container", this.getNextHighestDepth());
          > container.loadMovie("main.swf");
          > images.loadMovie("images.swf");

          So far, so good. I would encourage you, at this point in your code, to
          add a mechanism to "listen" for the completion of the loading process, both
          for main.swf and images.swf. If you want to use the MovieClip.loadMovie()
          method, like you're doing, you'll have to set up a loop of some sort --
          MovieClip.onEnterFrame or setInterval() -- to continuously check how many
          bytes have been loaded of these files against how many bytes they have
          total. Here's a short article that may help:

          http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded/

          > // center of the very first position of the swfs
          > this.onEnterFrame = function() {
          > container._x = Stage.width/2-472.5; // half the size of the main.swf is
          > subtracted for perfect centering.

          Here's a potential problem. I'm not seeing anything that would rotate
          an image, but you've set up a MovieClip.onEnterFrame loop here that doesn't
          seem to stop. For the duration of the movie -- from the time it loads to
          the time the visitor leaves -- you're continuously performing math against
          the container and images clips. My hunch is that you're doing it this way
          because your code isn't currently set up to wait for the content to load.
          Unfortunately, you're doubling your efforts by performing all this centering
          both here *and* in response to the Stage.onResize handler.

          > container._y = Stage.height/2-287.5; //
          > images._x = Stage.width/2.75; // divided to be off-center

          For lines like these, why not use MovieClip properties for the container
          and images movie clips? Rather than hard-coding 287.5, which means you'll
          have to change your ActionScript if you change the image, use the width of
          container itself ...

          container._y = Stage.height/2 - container._width/2;

          I realize you may have already tried that and found that it didn't work.
          If so, the reason it didn't work is almost certainly because container's
          content hadn't yet loaded, so _width was 0.

          > images._y = Stage.height/2.75;
          > // images._height = Stage.height;
          > // the line of code above is getting me in trouble. Adding this
          > makes the background images rotate!!!!!??????

          I can't see any reason why it would -- you've truly got a
          head-scratcher, here! -- but again, you're continusouly looping on these
          measurements while simultaneously measuring them on response to the
          Stage.onResize event. It may just turn out that cleaning up the code a bit
          fixes your problem. (Admittedly, what I said doesn't make any more sense
          than the fact that this problem is already happening, but I've encountered
          stranger issues on occasion. Sometimes programming is Zen, after all.)

          I recommend you clear out the above onEnterFrame loop and, instead,
          assign the Stage.onResize handler in response to content having loaded into
          the images clip. If you use a named function, rather than an anonymous
          literal, you'll be able to call that function once on load, and let onResize
          call it from then on as needed.

          e.g.
          // earlier in your code, so that the stageL object
          // and the custom function are scoped to the main
          // timeline (and thus available throughout the timeline)
          var stageL:Object = new Object();

          function centerContent():Void {
          container._x = Stage.width/2 - container._width/2;
          container._y = Stage.height/2 - container._height/2;
          images._x = Stage.width/2.75; // determine value that
          images._y = Stage.height/2.75; // works for you visually
          images._height = Stage.height;
          }
          stageL.onResize = centerContent;

          // inside a function that determines when
          // the external file has loaded for images
          centerContent();
          Stage.addListener(stageL);


          David Stiller
          Co-author, Foundation Flash CS3 for Designers
          http://tinyurl.com/2k29mj
          "Luck is the residue of good design."


          • 2. Re: Unwanted rotation
            Phyrexian Level 1
            Thanks. I found a solution via another forum that fixed it all.
            It was indeed a problem with the onEnterFrame code and the continuous loop it creates. It took too much memory (animations were laggy) and made things go wron apparantly.
            Check the result: http://www.bodysong.co.uk/tmp/tmp.html


            This is the correct actionscript (with loadclip).


            var images:MovieClip = createEmptyMovieClip("images", getNextHighestDepth());
            var container:MovieClip = createEmptyMovieClip("container", getNextHighestDepth());

            var mcLoader:MovieClipLoader = new MovieClipLoader();
            mcLoader.addListener(this);
            mcLoader.loadClip("main.swf", container);
            mcLoader.loadClip("images.swf", images);

            function onLoadInit(mc:MovieClip) {
            container._x = Stage.width/2-472.5; // deze groote is de grootte van de te laden SWF
            container._y = Stage.height/2-287.5; // idem zoals hierboven
            images._height = Stage.height;
            images._width = images._height/3*2;
            images._x = Stage.width/2.75; // groter dan 2 is meer naar links!
            images._y = Stage.height/2;
            }



            // coninue centreren van de mc "container" op de stage (in de browser)
            // zonder deze StageListener wordt de clip slechts gecentreerd wanneer je de muisknop loslaat
            var stageL:Object = new Object();
            stageL.onResize = function() {
            container._x = Stage.width/2-472.5;
            container._y = Stage.height/2-287.5;
            images._height = Stage.height;
            images._width = images._height/3*2;
            images._x = Stage.width/2.75;
            images._y = Stage.height/2;
            };
            Stage.addListener(stageL);
            • 3. Re: Unwanted rotation
              Level 7
              Phyrexian,

              > Thanks. I found a solution via another forum that fixed it all.

              Glad to hear it. :)

              > It was indeed a problem with the onEnterFrame code and the
              > continuous loop it creates. It took too much memory (animations
              > were laggy) and made things go wron apparantly.

              Best of luck with it! That rotation was a pretty odd manifestation of
              conflicting event handlers.


              David Stiller
              Adobe Community Expert
              Dev blog, http://www.quip.net/blog/
              "Luck is the residue of good design."