Solved

Change load image registration point

Posted on 2006-11-07
10
176 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
Comment Utility
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
Comment Utility
0
 

Author Comment

by:mingchih
Comment Utility
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
 
LVL 34

Expert Comment

by:Aneesh Chopra
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:mingchih
Comment Utility
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
Comment Utility
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
Comment Utility
wow, cool, thanks, I will let you know if I have other questions :) Thanks again
0
 

Author Comment

by:mingchih
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now