Solved

Change load image registration point

Posted on 2006-11-07
10
204 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
  • 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
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…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to how to record live broadcast.

820 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