6 Replies Latest reply on Apr 2, 2007 2:34 PM by bvillanyi

    Movie clip centers itself on upper left of screen

    bvillanyi
      I have a movie clip that I load via AS, but it always plays centered on the upper left corner of the window, instead of centered in the window itself. If I create a new instance of it manually on the stage (not using AS), it plays in the right place. How do I tell it where to position itself? The _x and _y properties don't seem to have any effect.

      Here's the code:

      var mc1:MovieClip;
      mc1 = this.createEmptyMovieClip("DR1", this.getNextHighestDepth());
      this.attachMovie("DR1", "mc1", this.getNextHighestDepth());
      mc1._x = 500;
      mc1._y = 500;
      mc1.play();

      Thanks,
      Beth
        • 1. Re: Movie clip centers itself on upper left of screen
          Rothrock Level 5
          You don't need both lines of code. Or maybe you do, but you've got craziness going on.

          On the main timeline you have a variable called mc1 which holds a reference to a newly created EMPTY movie clip.

          You also have attached to the main timeline a clip from the library which has a linkage of DR1 and is now called mc1.

          So basically there are two things called mc1 on the main timeline and that is getting Flash confused.

          I'm not really sure what you are trying to do, but that isn't it!
          • 2. Re: Movie clip centers itself on upper left of screen
            bvillanyi Level 1
            Thanks for your response. I'm new to this and I find the help files confusing.

            What I want to do is load the clip (DR1) at the beginning so that it's loaded and ready to play. Then in frame 113, I want it to play - plain and simple. The reason I want to use script to load and play it is that I want to load different clips based on some variables that are passed to the movie from the web page that calls it.

            I thought the empty clip creation was establishing an object, and then the attach command loaded the movie into the object. Obviously that is incorrect. Can you tell me what will accomplish the pre-load so that I can play the movie in frame 113?

            Thanks for your patience!

            Beth
            • 3. Movie clip centers itself on upper left of screen
              bvillanyi Level 1
              Okay, based on your response I did a little experimenting and found that if I got rid of the attachMovie line, it works! (Or at least I thought it was working)

              Unfortunately, when I first posted this as the answer, I didn't realize that I had physically loaded an instance of the clip on the timeline. The code below simply allowed that instance to play because nothing else was now interfering with it:

              This is the working code in frame 1:

              mc1 = this.createEmptyMovieClip("DR1", this.getNextHighestDepth());
              mc1._x = 500;
              mc1._y = 500;

              And at frame 113 the movie plays, and in the right place on the screen :-)

              So all of that above code, literally does nothing without the instance hardcoded on the timeline at the correct frame (113).

              I will repost with the problem again, this time without the instance of the clip already loaded in the timeline!

              Sorry about the confusion,
              Beth
              • 4. Re: Movie clip centers itself on upper left of screen
                Rothrock Level 5
                Couple of things. Don't start a new thread. We will get this sorted here.

                Second. Don't edit posts. A lot of folks here use newsreaders to view the threads. They won't see edits. So when you have new info just post that.

                I'm a bit confused. Are you trying to load an external file? Or are you trying to attach a clip that is already in your library, but has been set to export for actionscript?

                I'm really not sure exactly what you are trying to do, but I am certain you are a little confused. Hey, we've all been there!

                I'm thinking what you want to do is this:

                this.attachMovie("DR1","mc1",this.getNextHighestDepth(),{_x:500,_y:500});

                But I'm not sure.
                • 5. Re: Movie clip centers itself on upper left of screen
                  bvillanyi Level 1
                  Okay - points taken - thanks. Instead of a new post (which I was ready to hit Send on when I got your reply), here is the story from the top:

                  I have a movie clip called DR1 in the library with a name of DR1 and a linkage identifier of DR1.

                  I want this clip (or another similar one depending on run time parameters) to start playing in frame 113 of my movie. Right now I am concentrating on getting the clip to play, so I am hardcoding its name.

                  I have the following code in frame 1:

                  var mc1:MovieClip;
                  mc1 = this.createEmptyMovieClip("DR1", this.getNextHighestDepth());

                  mc1._x = 500;
                  mc1._y = 500;

                  And in frame 113:

                  mc1.play();

                  But when the movie gets to frame 113, nothing happens.

                  If I change the above code in frame 1 to the suggested code of

                  this.attachMovie("DR1","mc1",this.getNextHighestDepth(),{_x:500,_y:500});

                  then the first frame of the movie fills the screen at the right spot, but it never plays - it just stays there throughout the movie.

                  This clip plays fine if it is manually loaded into the timeline. What am I doing wrong?

                  If you can't see what's wrong with my code, does anyone have an example of a working flash movie that loads and plays a movie clip using action script that you are willing to share? I need to load one of a number of clips based on a parameter, so can't put it on the timeline manually.

                  Thanks,
                  Beth
                  • 6. Re: Movie clip centers itself on upper left of screen
                    bvillanyi Level 1
                    Okay, this is embarassing.

                    Moving the suggested code,

                    this.attachMovie("DR1","mc1",this.getNextHighestDepth(),{_x:500,_y:500});

                    to frame 113 made the clip start at the right time and display in the right place.

                    Removing the stop(); action from the first line of the clip allowed it to play! (I swear I don't know how it got there.)

                    I created a very simple example to show the problem I was having in order to post the actual files, and as that one worked, I was forced to re-examine my code one more time, including the clip. That's when I found the stop().

                    Thanks for all your help.

                    Beth