Solved

Change load image registration point

Posted on 2006-11-07
10
217 Views
Last Modified: 2012-05-05
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;
0
Comment
Question by:mingchih
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 17897357
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
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 17897366
0
 

Author Comment

by:mingchih
ID: 17900549
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 17903184
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
 

Author Comment

by:mingchih
ID: 17903250
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
 

Author Comment

by:mingchih
ID: 17903316
Hi, Aneesh

I just send you the fla file and maybe easier for you to see the whole code :) Thanks
0
 
LVL 34

Accepted Solution

by:
Aneesh Chopra earned 500 total points
ID: 17903538
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
 

Author Comment

by:mingchih
ID: 17904265
wow, cool, thanks, I will let you know if I have other questions :) Thanks again
0
 

Author Comment

by:mingchih
ID: 17904276
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
 

Author Comment

by:mingchih
ID: 17911090
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question