Change load image registration point

Hi, Experts

I have a code that load external jpg image. However, the image registration point is at top left. I wonder how to change the load image registration point to center at height and width. Thanks

::: code :::

      zoomMC = _loc1.createEmptyMovieClip("myTarget", 9999);
      zoomPicture = "netblue/zoom/"+_loc1.projects[this._parent.i]+".jpg";
      zoomMC.loadMovie(zoomPicture);
       // Below is the code set images position... with registration point at top left
      _loc1.zoomMC._x = (Stage.width-_loc1.zoomMC._width)/9.5;
      _loc1.zoomMC._y = (Stage.height-_loc1.zoomMC._height)/9.5;
Brian LinDesignerAsked:
Who is Participating?
 
Aneesh ChopraConnect With a Mentor Commented:
problem was that your fla was generating FLash 6 output, but to use MovieClipLoader Class you must export for FlashPlayer 7 with AS2.

change it according...
//
1.
goto File>Publish settings

2.
on Flash Tab, change version to 7 and Actionscirpt version 2.

3.
just replace complete code of Projects.fla, frame 2, with following:
--------------
var _loc1 = this;
//
function loadMe()
{
      myX = 0;
      myY = 0;
      gap = 100;
      max = 4;
      counter = 0;
      for (n=1; n<20; n++)
      {
            mc = _loc1.createEmptyMovieClip("myTarget"+n, 20+n);
            trace("Project list n = "+n);
            picture = "art/"+projects[n]+".jpg";
            mc.loadMovie(picture);
            if (counter>max)
            {
                  counter = 0;
                  myY = myY+gap;
            }
            // end if                      
            mc._x = myX+gap*counter;
            mc._y = myY;
            trace("counter:"+counter);
            ++counter;
      }
      // end of for
}
// End of the function
function buildMenu()
{
      myX = 0;
      myY = 0;
      gap = 100;
      max = 4;
      counter = 0;
      for (i=1; i<20; i++)
      {
            mc = _loc1.attachMovie("button", "button"+i, 50+i);
            trace("Menu list --   "+i);
            mc.i = i;
            _loc1.myName = i;
            _loc1.myName = _loc1.projects[i];
            mc.person.text = _loc1.myName;
            trace("myName --   "+myName);
            _loc1.n = i;
            if (counter>max)
            {
                  counter = 0;
                  myY = myY+gap;
            }
            // end if                      
            mc._x = myX+gap*counter;
            mc._y = myY;
            trace("counter:"+counter);
            ++counter;
      }
      // end of for
}
// End of the function
function buttonOver()
{
      _loc1 = this._parent._parent;
      trace("which one is roll over now --  "+this._parent);
      this._parent.gotoAndStop(6);
      _loc1.myName = _loc1.projects[i];
      //_loc1["button"+i].gotoAndStop(1);
}
// End of the function
function buttonClick()
{
      _loc1 = this._parent._parent;
      //
      _loc1.createEmptyMovieClip("zoomMC12", 9999);
      _loc1.zoomMC12._x = 200;
      _loc1.zoomMC12._y = 200;
      trace("Click on button  "+this);
      zoomMC = _loc1.zoomMC12.createEmptyMovieClip("myTarget", 9999);
      trace(" import Project bigger image n = "+this._parent.i);
      zoomPicture = "art/zoom/"+String(_loc1.projects[this._parent.i])+".jpg";
      //
      _loc1.mcLoader.loadClip(zoomPicture, zoomMC);
      //_loc1.zoomMC._x = 163;
      //_loc1.zoomMC._y = 100;
      // end of for
}
//
var myListener = new Object();
myListener.onLoadInit = function(target_mc)
{
      target_mc._x = -(target_mc._width/2);
      target_mc._y = -(target_mc._height/2);
};
var mcLoader = new MovieClipLoader();
mcLoader.addListener(myListener);
//
// End of the function
var projects = new Array("", "Josephine", "YaChing", "Samajaree", "Ginger", "Kate", "Brandon", "JungHwan", "SunHwan", "RuiJun", "Brian", "JungEun", "Sharon", "Mulee", "Yuke", "Yohanna", "Mark", "Caroline", "MeiChun", "GarMan", "Martha");
var scrolling = 0;
var howMany = projects.length;
var n = 1;
loadMe();
buildMenu();
var myName;
stop();
--------------

--Aneesh

0
 
Aneesh ChopraCommented:
HI,

to set an image reg point in center, you should load the image in a movieClip inside another movieclip.
for example,

load movie in "_root.container.mc"
----------
_root.container.mc.loadMovie("image0.jpg");
---------
now check for loading completion and move the "_root.container.mc" x,y to in minus (width/2) and (height)/2

_root.container.mc._x = -_root.container.mc._width/2;
_root.container.mc._y = _root.container.mc._height/2;

now your "container" movie got its reg point in center..

I hope it would beclear

-Aneesh
0
 
Aneesh ChopraCommented:
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Brian LinDesignerAuthor Commented:
okay, i try it ... but not really working, could you take a look at this part, thanks

function buttonClick() {
      _loc1 = this._parent._parent;
      _loc1.createEmptyMovieClip("myTarget", 9999);
      _loc1.myTarget._x = 163;
      _loc1.myTarget._y = 100;
      child = myTarget.createEmptyMovieClip("child", _loc1.target_mc.getNextHighestDepth());
      tlistener = new Object();
      tlistener.onLoadInit = function(target_mc) {
            _loc1.target_mc._x = -(_loc1.target_mc._width/2);
            _loc1.target_mc._y = -(_loc1.target_mc._height/2);

      };
      image_mcl = new MovieClipLoader();
      image_mcl.addListener(tlistener);
      image_mcl.loadClip(zoomPicture, child);
      zoomPicture = "netblue/zoom/"+_loc1.projects[this._parent.i]+".jpg";
}
0
 
Aneesh ChopraCommented:
found following issues,

1.
you should not use "_loc1." inside "onLoadInit" function, here function is getting movieClip reference as parameter...

2.
your code is using "zoomPicture" variable before assigning it a value, you should first assign it pciture path then variable should be used.

fixed code is here:

---------------
function buttonClick() {
     _loc1 = this._parent._parent;
     _loc1.createEmptyMovieClip("myTarget", 9999);
     _loc1.myTarget._x = 163;
     _loc1.myTarget._y = 100;
     child = myTarget.createEmptyMovieClip("child", _loc1.target_mc.getNextHighestDepth());
     tlistener = new Object();
     tlistener.onLoadInit = function(target_mc) {
          target_mc._x = -(target_mc._width/2);
          target_mc._y = -(target_mc._height/2);

     };
     image_mcl = new MovieClipLoader();
     image_mcl.addListener(tlistener);
     zoomPicture = "netblue/zoom/"+_loc1.projects[this._parent.i]+".jpg";
    image_mcl.loadClip(zoomPicture, child);
 }
------------
-Aneesh
0
 
Brian LinDesignerAuthor Commented:
Hi, Aneesh:

I use your code and made similar one with success to load the bigger images...but each bigger image's registration point is still at top left.....maybe something to do with these two lines of code below ?
--------------------------------------------------------------------------------
      _loc1.zoomMC._x = -(_loc1.zoomMC._width/2);
      _loc1.zoomMC._y = -(_loc1.zoomMC._height/2);
--------------------------------------------------------------------------------
:::CODE:::
function buttonClick() {
      _loc1 = this._parent._parent;
      _loc1.createEmptyMovieClip("zoomMC12", 9999);
      zoomMC12._x = 200;
      zoomMC12._y = 300;
      trace("Click on button  "+this);
      zoomMC = zoomMC12.createEmptyMovieClip("myTarget", 9999);
      trace(" import Project bigger image n = "+this._parent.i);
      zoomPicture = "netblue/zoom/"+_loc1.projects[this._parent.i]+".jpg";
      zoomMC.loadMovie(zoomPicture, zoomMC1);
      _loc1.zoomMC._x = -(_loc1.zoomMC._width/2);
      _loc1.zoomMC._y = -(_loc1.zoomMC._height/2);
}
--------------------------------------------------------------------------------
0
 
Brian LinDesignerAuthor Commented:
Hi, Aneesh

I just send you the fla file and maybe easier for you to see the whole code :) Thanks
0
 
Brian LinDesignerAuthor Commented:
wow, cool, thanks, I will let you know if I have other questions :) Thanks again
0
 
Brian LinDesignerAuthor Commented:
Can I ask what did you do to this part to make it all work ?

function buttonClick() {
      _loc1 = this._parent._parent;
      //
      _loc1.createEmptyMovieClip("zoomMC12", 9999);
      _loc1.zoomMC12._x = 200;
      _loc1.zoomMC12._y = 200;
      trace("Click on button  "+this);
      zoomMC = _loc1.zoomMC12.createEmptyMovieClip("myTarget", 9999);
      trace(" import Project bigger image n = "+this._parent.i);
      zoomPicture = "netblue/zoom/"+String(_loc1.projects[this._parent.i])+".jpg";
      //
      _loc1.mcLoader.loadClip(zoomPicture, zoomMC);
      //_loc1.zoomMC._x = 163;
      //_loc1.zoomMC._y = 100;
      // end of for
}
//
var myListener = new Object();
myListener.onLoadInit = function(target_mc) {
      target_mc._x = -(target_mc._width/2);
      target_mc._y = -(target_mc._height/2);
};
var mcLoader = new MovieClipLoader();
mcLoader.addListener(myListener);
0
 
Brian LinDesignerAuthor Commented:
Hi, Aneesh

I post another question relate to this one.... please take a look at http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q_22055630.html

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.