5 Replies Latest reply on Mar 21, 2008 9:17 AM by Newsgroup_User

    changing x and y position of a loded swf

    joshuantaylor Level 1
      I know this is so basic, and I have googled and looked at help docs, which is helpful, but I still can't see the answer to my questions specifically.
      I am loading an external swf into my movie, and the default x y coordinates are 0,0.
      I want to make the coordinates 450, 0.
      How do I do that. Here is teh code.
      // ----------------<MCL>--------------------------\\
      var myMCL:MovieClipLoader = new MovieClipLoader();
      var myListener:Object = new Object();

      myMCL.addListener(myLisntener);
      // ----------------</MCL>--------------------------\\

      // loads the references flash player
      myMCL.loadClip("reference.swf", 5);

      thanks so much. I hope that makes sense. I just want the reference.swf file to be loaded in on layer 5--- 450 pixels form the left.
      thanks again!
        • 1. Re: changing x and y position of a loded swf
          Level 7
          joshuataylordesign,

          var myMCL:MovieClipLoader = new MovieClipLoader();

          So far, this is fine. You're declaring a variable that happens to be
          named myMCL, and it refers to an instance of the MovieClipLoader class.
          What that means is that your variable, myMCL, has available to it all the
          functionality defined by that class in the documentation. The
          characteristics of this object (and this goes for all classes) are called
          properties; the things it can do are called methods; the things it can react
          to are called events.

          You're going to use the loadClip() method, and you're going to use the
          onLoadInit event. Let's take care of the event first.

          In AS2, the mechanics of event handling aren't always consistent. In
          this case, you're doing to need a go-between object -- just an Object
          instance -- to act as the liaison between your myMCL object and and your
          Object object.

          var myListener:Object = new Object();

          That line does it. So now you have myMCL, which is an instance of
          MovieClipLoader, and myListener, which is an instance of Object.

          When the onLoadInit event occurs, you want something to happen, so
          you'll need to assign an event to the myListener object to communicate your
          intentions on behalf of myMCL.

          myListener.onLoadInit = function():Void {
          // instructions here
          }

          What you want this function to *do* is to move the loaded clip to a
          certain horizontal position. Well, your loaded clip is an instance of the
          MovieClip class, so it has available to it all the properties, methods, and
          events of that class -- including an _x property. How can you get a
          *reference* to the loaded clip? That comes by way of a parameter to the
          function you're assigning to the onLoadInit event. This parameter is passed
          into the function automatically for you, so if you want to use it, just tap
          into it:

          myListener.onLoadInit = function(mc:MovieClip):Void {
          mc._x = 450;
          }

          And with that out of the way, you associate this myListener object with
          its companion object, myMCL:

          myMCL.addListener(myListener);

          Finally, invoke the loadClip() method on your myMCL instance:

          myMCL.loadClip("reference.swf", 5);

          Here it is, all together:

          var myMCL:MovieClipLoader = new MovieClipLoader();

          var myListener:Object = new Object();
          myListener.onLoadInit = function(mc:MovieClip):Void {
          mc._x = 450;
          }
          myMCL.addListener(myListener);

          myMCL.loadClip("reference.swf", 5);


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


          • 2. Re: changing x and y position of a loded swf
            joshuantaylor Level 1
            David,
            Wow, thank you for the in depth explanation. I tried to follow the best I could, and I think I did a pretty good job:). Unfortunately, it still does not work. All I did was take the final code you have there, and I put it on the as layer in frame 1.
            Is there more I am supposed to do? Or is there something else I am missing.

            Also, is the only change you made to my original code to add the :
            myListener.onLoadInit = function(mc:MovieClip):Void {
            mc._x = 450;
            }

            ?
            thanks again for your help!
            • 3. Re: changing x and y position of a loded swf
              Level 7
              joshuataylordesign,

              > Wow, thank you for the in depth explanation.

              Sure thing. :)

              > I tried to follow the best I could, and I think I did a pretty
              > good job:). Unfortunately, it still does not work.

              It works for me, but obviously all the "i"s need to be dotted and all
              the "t"s crossed. Are you working with ActionScript 2.0?

              > All I did was take the final code you have there, and I put it
              > on the as layer in frame 1.

              Yup. That's what I'm doing in my own test file (and, of course, there's
              a test SWF named reference.swf).

              > Is there more I am supposed to do? Or is there something
              > else I am missing.

              Are your publish settings cofigured for ActionScript 2.0 and Flash
              Player 7 or higher? The MovieClipLoader class requires at least Flash
              Player 7.

              > Also, is the only change you made to my original code to add the :
              > myListener.onLoadInit = function(mc:MovieClip):Void {
              > mc._x = 450;
              > }

              Yes, that's the only addition, and it's the part responsible for doing
              the actual moving of the loaded SWF.


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


              • 4. Re: changing x and y position of a loded swf
                joshuantaylor Level 1
                hmm. I am very confused then. I believe I have all of that correct. Here is the code that I have on frame 1, layer 1. It loads in the reference.swf file, but it is still at 0,0

                var myMCL:MovieClipLoader = new MovieClipLoader();

                var myListener:Object = new Object();
                myListener.onLoadInit = function(mc:MovieClip):Void {
                mc._x = 450;
                }
                myMCL.addListener(myListener);

                myMCL.loadClip("reference.swf", 5);

                thanks again. Hopefully you see something here
                • 5. Re: changing x and y position of a loded swf
                  Level 7
                  joshuataylordesign,

                  > Here is the code that I have on frame 1, layer 1. It loads in the
                  > reference.swf file, but it is still at 0,0
                  >
                  > var myMCL:MovieClipLoader = new MovieClipLoader();
                  >
                  > var myListener:Object = new Object();
                  > myListener.onLoadInit = function(mc:MovieClip):Void {
                  > mc._x = 450;
                  > }
                  > myMCL.addListener(myListener);
                  >
                  > myMCL.loadClip("reference.swf", 5);

                  That's it. That works for me just fine, for SWFs configured for
                  ActionScript 2.0 in Flash Player 7 or higher. If you write to me off list,
                  I'll send you my test FLAs. Visit my website, quip.net, and use the contact
                  form to give me a shout.


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