10 Replies Latest reply on May 11, 2011 2:51 AM by aneelbakshi

    align a movieclip loaded?????

    melas076 Level 1

      Dear all,

       

      I did loadmovie an external swf and it works well.

       

      i would like to know how can i align with a MC which loaded ????

      it align a center of the main movie.......!!!

       

       

      i would appreciate your help!!!!!

       

      regards,

      MELAS

        • 1. Re: align a movieclip loaded?????
          kglad-zqbLf4 Level 3

          AFTER loading is complete:

           

          yourtarget_mc._x=(Stage.width-yourtarget_mc._width)/2;

          yourtarget_mc._y=(Stage.height-yourtarget_mc._height)/2;

          1 person found this helpful
          • 2. Re: align a movieclip loaded?????
            Ned Murphy Adobe Community Professional & MVP

            Your question is not clearly worded.  You need to wait until the object is loaded before you can align it, unless you know the dimensions ahead of time and want to build that into the code.  To wait for an object to be loaded you will need to use the MovieClipLoader.loadClip() method with a listener assigned to it instead of loadMovie()

            • 3. Re: align a movieclip loaded?????
              melas076 Level 1

              dear all,

               

              I did but it is still the same issue.....

               

              what can i try else?

               

              melas.

              • 4. Re: align a movieclip loaded?????
                kglad Adobe Community Professional & MVP

                i'll bet you didn't do it correctly.

                 

                show just your loading code, the code that ensures loading is complete and the centering code.

                • 5. Re: align a movieclip loaded?????
                  melas076 Level 1

                  this is the code for the index.swf :

                   

                  this.LOADmc.scale ="noscale";
                  this.LOADmc.align = "LT";

                   

                  stop();
                  function loadXML(loaded) {

                   

                  if (loaded) {

                   

                  xmlNode = this.firstChild;
                  links = [];
                  description = [];
                  thumbnails = [];
                  total = xmlNode.firstChild.childNodes.length;
                  for (i=0; i<total; i++) {

                   

                  links[i] = xmlNode.firstChild.childNodes[i].attributes.datas;
                  description[i] = xmlNode.firstChild.childNodes[i].attributes.label;
                  thumbnails[i] = xmlNode.firstChild.childNodes[i].attributes.thumbs;
                  thumbnails_fn(i);

                   

                  }

                   

                  } else {

                   

                  content = "file not loaded!";

                   

                  }

                   

                  }
                  xmlData = new XML();
                  xmlData.ignoreWhite = true;
                  xmlData.onLoad = loadXML;
                  xmlData.load("data.xml");

                   

                     
                  function thumbnails_fn(k) {

                   

                  this.thumbnail_mc.createEmptyMovieClip("t"+k, this.thumbnail_mc.getNextHighestDepth());
                  tlistener = new Object();
                  tlistener.onLoadInit = function(target_mc) {

                   

                  target_mc._x = (eval("this.thumbnail_mc.t"+k)._width+20)*k;
                  target_mc.pictureValue = k;
                  a = xmlNode.firstChild.childNodes[p].attributes.datas;
                  target_mc.onRelease = function() {

                   

                  LOADmc.loadMovie(a);

                   

                  trace(xmlNode.firstChild.childNodes[p].attributes.datas);
                  p = this.pictureValue;
                  //nextImage();

                   

                  };
                  target_mc.onRollOver = function() {

                   

                  this._alpha = 90;

                   

                  };
                  target_mc.onRollOut = function() {

                   

                  this._alpha = 100;

                   

                  };

                   

                  };
                  image_mcl = new MovieClipLoader();
                  image_mcl.addListener(tlistener);
                  image_mcl.loadClip(thumbnails[k], "thumbnail_mc.t"+k);

                   

                  }

                   

                  LOADmc._x=(Stage.width-LOADmc._width)/2;
                  LOADmc._y=(Stage.height-LOADmc._height)/2;

                   

                   

                  and this is another code for main.as of the main.swf:

                   

                  private var node:XMLNode;
                      public static var thC:MovieClip;
                     
                      public static var btC:MovieClip;
                      public static var bigPict:Number;
                      public static var smallThumb:Number;
                      public static var buttonState:Number;
                      public static var currentButton:Number = 1;
                      public static var doneRght:Number;
                      public static var ld:Number;
                      public static var tr:Number =0;
                      public var sus:Number = 20;
                      public var drp:Number = 20;
                     
                      public static var resized:Number=1;
                      public static var init:Number = 0;
                      private var sw:Number;
                      private var sh:Number;
                     
                      public function main(n) {
                          _root["pr"]._x = Stage.width/2;
                          _root["pr"]._y = Stage.height/2;
                          //_root["pr"]._x = 0;
                  //        _root["pr"]._y = 0;
                          tr = 0;
                          smallThumb = 0;
                          buttonState = 0;
                          node = n;
                          _root.attachMovie("BCK","bk",_root.getNextHighestDepth());
                          _root["bk"]._width = Stage.width/2;
                          _root["bk"]._height = Stage.height/2;
                          _root["bk"]._alpha = 10;
                          _root.createEmptyMovieClip("GAL",_root.getNextHighestDepth());
                          /*_root["GAL"]._xscale = 0;
                          _root["GAL"]._yscale = 0;*/
                         
                          _root["GAL"].attachMovie("PictHolder","IMAGE",_root["GAL"].getNextHighestDepth());
                          _root["GAL"].attachMovie("Scroller","LEFT_SCROLLER",_root["GAL"].getNextHighestDepth());
                          _root["GAL"].attachMovie("Scroller2","RIGHT_SCROLLER",_root["GAL"].getNextHighestDepth()) ;
                         
                          //_root["GAL"]["IMAGE"].arrange();
                         
                          _root["GAL"]["LEFT_SCROLLER"].setNode(node);
                          _root["GAL"]["IMAGE"].setNode(node.firstChild);
                         
                          _root["GAL"]["RIGHT_SCROLLER"].setNode(node.firstChild.firstChild.firstChild,node.firstCh ild.firstChild.lastChild.firstChild,node.firstChild.firstChild.attributes.ProductTitle,nod e.firstChild.firstChild.lastChild.attributes.linkname);
                          //_root["GAL"]["RIGHT_SCROLLER"].setNode();
                          //trace(node.firstChild.firstChild.lastChild.attributes.linkname);
                          _root["GAL"]["RIGHT_SCROLLER"]._x = 243+640-_root["GAL"]["RIGHT_SCROLLER"]._width;
                         
                          bigImage.counter["txt"].text = "1 | 1/"+rightScroller.thumbCount;
                          _root["GAL"]["LEFT_SCROLLER"]._x = 2;
                          _root["GAL"]["LEFT_SCROLLER"]._y = 2;
                          _root["GAL"]["IMAGE"]._x = 243;
                          _root["GAL"]["IMAGE"]._y = _root["GAL"]["LEFT_SCROLLER"]._y+2;

                   

                          var myListener:Object = new Object();
                          myListener.onResize = Delegate.create(this, cont);
                          cont();
                          Stage.addListener(myListener);

                   

                      }
                         
                      private function cont() {
                         
                          if (resized != 1) {
                              resized = 1;
                          }
                         
                          _root["bk"]._width = Stage.width/2;
                          _root["bk"]._height = Stage.height/2;
                         
                          sw = Stage.width-251;
                          sh = Stage.height-100;
                         
                          if (sw<640) {
                              sw = 640;
                          }
                          if (sh<480) {
                              sh = 480;
                          }
                         
                                 
                          _root["GAL"]["IMAGE"].maxw = sw;
                          _root["GAL"]["IMAGE"].maxh = sh;

                   

                         
                      }
                  }

                  • 6. Re: align a movieclip loaded?????
                    aneelbakshi Level 1

                    I use this to achive it

                     

                    function initPreloading() {
                        var loadListener:Object = new Object();
                        preloader_mc._visible = true;
                        controllDisable_btn._visible = true;
                        loadListener.onLoadComplete = function(target_mc:MovieClip, httpStatus:Number):Void  {
                            preloader_mc._visible = false;
                            controllDisable_btn._visible = false;
                        };
                        loadListener.onLoadStart = function(target_mc:MovieClip) {
                            loader_mc.gotoAndStop(1);
                        };

                     

                        loadListener.onLoadInit = function(target_mc:MovieClip):Void  {
                            loader_mc.play();

                     

                           loader_mc.onEnterFrame = function() {
                                if (loader_mc._width>0) {
                                   
                    alignSWF();
                                    delete loader_mc.onEnterFrame;
                                    sample.text = loader_mc._width+" __ "+loader_mc._height;
                                }
                            };

                        };

                     

                     


                        var mcLoader:MovieClipLoader = new MovieClipLoader();
                        mcLoader.addListener(loadListener);

                     

                        var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
                        mcLoader.loadClip(swfPath,loader_mc);
                    }

                     

                     

                    function alignSWF() {
                       loader_mc._x = align_mc._x+(align_mc._width-loader_mc._width)/2;
                        loader_mc._y = align_mc._y+(align_mc._height-loader_mc._height)/2;

                      
                    }

                     

                    its sample of working code. May b it help you

                    • 7. Re: align a movieclip loaded?????
                      melas076 Level 1

                      thanks Anil,

                       

                      But i would like to know where can i put this sample code? in index or main?

                       

                      regards,

                      MELAS

                      • 8. Re: align a movieclip loaded?????
                        aneelbakshi Level 1

                        You can use this technique where you are trying to align your movieclip.

                         

                        LOADmc._x=(Stage.width-LOADmc._width)/2;
                        LOADmc._y=(Stage.height-LOADmc._height)/2;

                         

                        if this is your attempt to align the movie clip then you should use here

                         

                        The idea is that when u call any loadMovie or mcloader.load function

                         

                        at that time u can start a timer or enterframe as well and keep checking height or width of loaded movieclip in that enterframe/timer. as soon as u get these values more then 0 clear the interval and align that movie. and most importently u need have some alpha =0 graphic patch(same size as your swf stage) on the first frame of your swf and no item on that frame should be outside of stage area.

                         

                        coz your movie height and width is depandent on what content you have on your first frame

                         

                        because stage resize itself according to content

                        1 person found this helpful
                        • 9. Re: align a movieclip loaded?????
                          melas076 Level 1

                          dear Anil,

                           

                          i don't understand and i am beginner in actionscript 2......

                           

                          so in the first frame in my movieclip, i have an animation which it runs to frame 65 and then it load a LOADmc.

                           

                          frame 65 i have this code:

                           

                          //LOADmc._lockroot = true;
                          //LOADmc.scale ="noscale";
                          //LOADmc.align = "LT";

                           

                          stop();
                          function loadXML(loaded) {

                           

                          if (loaded) {

                           

                          xmlNode = this.firstChild;
                          links = [];
                          description = [];
                          thumbnails = [];
                          total = xmlNode.firstChild.childNodes.length;
                          for (i=0; i<total; i++) {

                           

                          links[i] = xmlNode.firstChild.childNodes[i].attributes.datas;
                          description[i] = xmlNode.firstChild.childNodes[i].attributes.label;
                          thumbnails[i] = xmlNode.firstChild.childNodes[i].attributes.thumbs;
                          thumbnails_fn(i);
                          //trace(xmlNode.firstChild.childNodes[1].attributes.thumbs);
                          //trace(links[i]);
                          }

                           

                           

                           

                          } else {

                           

                          content = "file not loaded!";

                           

                          }

                           

                          }
                          xmlData = new XML();
                          xmlData.ignoreWhite = true;
                          xmlData.onLoad = loadXML;
                          xmlData.load("data.xml");
                          /////////////////////////////////////

                          function thumbnails_fn(k) {

                           

                          this.thumbnail_mc.createEmptyMovieClip("t"+k, this.thumbnail_mc.getNextHighestDepth());
                          tlistener = new Object();
                          tlistener.onLoadInit = function(target_mc) {

                           

                          target_mc._x = (eval("this.thumbnail_mc.t"+k)._width+20)*k;
                          target_mc.pictureValue = k;
                          a = xmlNode.firstChild.childNodes[p].attributes.datas;
                          target_mc.onRelease = function() {

                           

                          LOADmc.loadMovie(a);

                           

                          trace(xmlNode.firstChild.childNodes[p].attributes.datas);
                          p = this.pictureValue;
                          //nextImage();

                           

                          };
                          target_mc.onRollOver = function() {

                           

                          this._alpha = 90;

                           

                          };
                          target_mc.onRollOut = function() {

                           

                          this._alpha = 100;

                           

                          };

                           

                          };
                          image_mcl = new MovieClipLoader();
                          image_mcl.addListener(tlistener);
                          image_mcl.loadClip(thumbnails[k], "thumbnail_mc.t"+k);

                           

                          }

                          LOADmc._x=(alignmc.width-LOADmc._width)/2;
                          LOADmc._y=(alignmc.height-LOADmc._height)/2;

                          • 10. Re: align a movieclip loaded?????
                            aneelbakshi Level 1

                            //LOADmc._lockroot = true;
                            //LOADmc.scale ="noscale";
                            //LOADmc.align = "LT";

                             

                            stop();
                            function loadXML(loaded) {

                             

                            if (loaded) {

                             

                            xmlNode = this.firstChild;
                            links = [];
                            description = [];
                            thumbnails = [];
                            total = xmlNode.firstChild.childNodes.length;
                            for (i=0; i<total; i++) {

                             

                            links[i] = xmlNode.firstChild.childNodes[i].attributes.datas;
                            description[i] = xmlNode.firstChild.childNodes[i].attributes.label;
                            thumbnails[i] = xmlNode.firstChild.childNodes[i].attributes.thumbs;
                            thumbnails_fn(i);
                            //trace(xmlNode.firstChild.childNodes[1].attributes.thumbs);
                            //trace(links[i]);
                            }

                             

                             

                             

                            } else {

                             

                            content = "file not loaded!";

                             

                            }

                             

                            }
                            xmlData = new XML();
                            xmlData.ignoreWhite = true;
                            xmlData.onLoad = loadXML;
                            xmlData.load("data.xml");
                            /////////////////////////////////////

                             

                            function thumbnails_fn(k) {

                             

                            this.thumbnail_mc.createEmptyMovieClip("t"+k, this.thumbnail_mc.getNextHighestDepth());
                            tlistener = new Object();
                            tlistener.onLoadInit = function(target_mc) {

                             

                            target_mc._x = (eval("this.thumbnail_mc.t"+k)._width+20)*k;
                            target_mc.pictureValue = k;
                            a = xmlNode.firstChild.childNodes[p].attributes.datas;
                            target_mc.onRelease = function() {

                             

                            LOADmc.loadMovie(a);

                             

                            this.onEnterFrame=function(){

                            if(LOADmc._width>0){

                            LOADmc._x=(alignmc.width-LOADmc._width)/2;
                            LOADmc._y=(alignmc.height-LOADmc._height)/2;

                            }

                            }

                             

                             

                            trace(xmlNode.firstChild.childNodes[p].attributes.datas);
                            p = this.pictureValue;
                            //nextImage();

                             

                            };
                            target_mc.onRollOver = function() {

                             

                            this._alpha = 90;

                             

                            };
                            target_mc.onRollOut = function() {

                             

                            this._alpha = 100;

                             

                            };

                             

                            };
                            image_mcl = new MovieClipLoader();
                            image_mcl.addListener(tlistener);
                            image_mcl.loadClip(thumbnails[k], "thumbnail_mc.t"+k);

                             

                            }

                             

                             

                             

                             

                            PLease find my code in boldI am assuming that u r trying to align LOADmc .