PDA

View Full Version : Dynamicaly changing the registration point of a MC?



tizzle
September 24th, 2004, 08:20 AM
For a simple image editing application in Flash (AS 2.0) i'm looking for a method to change the registration point of a MC dynamically. This is needed since the imageHolder clip that i loadMovie() my jpeg in needs to be rotated, scaled etc. after it has been placed on the scene, and it's a drag to correctly center the image on each event based on a point in the upper left corner instead of simply the middle of the image. trust me on that one ;)

I have tried simple loading the jpeg into a MC that already has it's registration point centered but this does not seem to matter.

Any ideas/tips?

tizzle
September 27th, 2004, 05:15 AM
Did i fail to explain properly or is there simply no way to do this?

stringy
September 27th, 2004, 07:12 AM
Did i fail to explain properly or is there simply no way to do this?
You can`t really change the registration point.
This code (written by someone else on another forum) may help.

var MCP = MovieClip.prototype;
MCP._xreg = MCP._yreg=0;
MCP.setPropRel = function(prop, amount) {
var a = {x:this._xreg, y:this._yreg};
this.localToGlobal(a);
this._parent.globalToLocal(a);
this[prop] = amount;
var b = {x:this._xreg, y:this._yreg};
this.localToGlobal(b);
this._parent.globalToLocal(b);
this._x -= b.x-a.x;
this._y -= b.y-a.y;
};
MCP.set_x2 = function(v) {
var a = {x:this._xreg, y:this._yreg};
this.localToGlobal(a);
this._parent.globalToLocal(a);
this._x += v-a.x;
};
MCP.get_x2 = function() {
var a = {x:this._xreg, y:this._yreg};
this.localToGlobal(a);
this._parent.globalToLocal(a);
return a.x;
};
MCP.set_y2 = function(v) {
var a = {x:this._xreg, y:this._yreg};
this.localToGlobal(a);
this._parent.globalToLocal(a);
this._y += v-a.y;
};
MCP.get_y2 = function() {
var a = {x:this._xreg, y:this._yreg};
this.localToGlobal(a);
this._parent.globalToLocal(a);
return a.y;
};
MCP.set_xscale2 = function(v) {
this.setPropRel("_xscale", v);
};
MCP.get_xscale2 = function() {
return this._xscale;
};
MCP.set_yscale2 = function(v) {
this.setPropRel("_yscale", v);
};
MCP.get_yscale2 = function() {
return this._yscale;
};
MCP.set_rotation2 = function(v) {
this.setPropRel("_rotation", v);
};
MCP.get_rotation2 = function() {
return this._rotation;
};
MCP.get_xmouse2 = function() {
return this._xmouse-this._xreg;
};
MCP.get_ymouse2 = function() {
return this._ymouse-this._yreg;
};
with (MCP) {
addProperty("_x2", get_x2, set_x2);
addProperty("_y2", get_y2, set_y2);
addProperty("_xscale2", get_xscale2, set_xscale2);
addProperty("_yscale2", get_yscale2, set_yscale2);
addProperty("_rotation2", get_rotation2, set_rotation2);
addProperty("_xmouse2", get_xmouse2, null);
addProperty("_ymouse2", get_ymouse2, null);
}
ASSetPropFlags(MCP, null, 1);
delete MCP;
//mc._xreg = 100;
//mc._yreg = 70;
//mc._rotation2 = 60;
//mc._x2;
//mc._y2 ;
//to position the movie clip according to the new reg point
//mc._xscale2;
//mc._yscale2 ;

pom
September 27th, 2004, 11:06 AM
Wow. If this works, it goes straight to the Best of Kirupa :ninja:

tizzle
September 28th, 2004, 06:43 AM
i make (and delete) the prototype clip when the movie starts using above code, then i put everything i need on the scene, and finally i center the MC using the newly available attributes. Pretty nifty... thx Stringy! :king:

stringy
September 28th, 2004, 11:44 AM
i make (and delete) the prototype clip when the movie starts using above code, then i put everything i need on the scene, and finally i center the MC using the newly available attributes. Pretty nifty... thx Stringy! :king:
Welcome - and a big thanks to the person who took the time to write it and share.

zooked
August 26th, 2005, 06:11 AM
I have the same problem. after pasting the code in the first frame what else shoul i do to make my mc rotate according to the new co-ordinates. should i change the values of:
//mc._xreg = 100;
//mc._yreg = 70;
//mc._rotation2 = 60;
//mc._x2;
//mc._y2 ;

to my mc's values? i trying to make my mc rotate continuously on cick of a button. my mc still rotates according to the old registration points. can you help?

stringy
August 27th, 2005, 05:39 AM
I have the same problem. after pasting the code in the first frame what else shoul i do to make my mc rotate according to the new co-ordinates. should i change the values of:
//mc._xreg = 100;
//mc._yreg = 70;
//mc._rotation2 = 60;
//mc._x2;
//mc._y2 ;

to my mc's values? i trying to make my mc rotate continuously on cick of a button. my mc still rotates according to the old registration points. can you help?
yes, just change to your values

eg/
btn.onPress = function() {
mc._xreg = 75;
mc._yreg = 75;
mc.onEnterFrame = function() {
this._rotation2++;
};
};

j0haan
August 30th, 2005, 06:50 PM
hello.. i have a problem with this code.
i can only change the registration point when i push a button but not when im doing it in a function. :h:
can i set the registration point on a empty movieclip? because that's what i'm trying to do and it won't work.
please help me someone.

stringy
September 1st, 2005, 12:10 PM
hello.. i have a problem with this code.
i can only change the registration point when i push a button but not when im doing it in a function. :h:
can i set the registration point on a empty movieclip? because that's what i'm trying to do and it won't work.
please help me someone.
you can`t set the registration point until you have loaded something into it.

mnbvcxz
April 2nd, 2007, 05:55 PM
how do i access any other nested movieclips which i had in that one?

FizixMan
April 2nd, 2007, 06:16 PM
myMovieClip["myChildClipName"]["myChildChildClipName"][etc...][etc...]

or


myMovieClip.myChildClipName.myChildChildClipName.e tc.etc

kalexand
May 16th, 2007, 09:23 AM
could someone explain how the above code is used? i've been redirected to this very post, but can't quite get it..

cyberkafka
August 21st, 2007, 07:05 AM
Great code that solves the problem of setting a registration point dynamically and shows the use of prototype.
Many thanks
:party:

vinodvv
November 21st, 2007, 05:44 AM
Here is the URL for proof http://www.darronschall.com/weblog/archives/000054.cfm
. check the comment section


You can`t really change the registration point.
This code (written by someone else on another forum) may help.
ActionScript Code:

var MCP = MovieClip.prototype;
MCP._xreg = MCP._yreg=0;
MCP.setPropRel = function(prop, amount) {
var a = {x:this._xreg, y:this._yreg};
this.localToGlobal(a);
this._parent.globalToLocal(a);
this[prop] = amount;
var b = {x:this._xreg, y:this._yreg};
this.localToGlobal(b);
this._parent.globalToLocal(b);
this._x -= b.x-a.x;
this._y -= b.y-a.y;
};
MCP.set_x2 = function(v) {
var a = {x:this._xreg, y:this._yreg};
this.localToGlobal(a);
this._parent.globalToLocal(a);
this._x += v-a.x;
};
MCP.get_x2 = function() {
var a = {x:this._xreg, y:this._yreg};
this.localToGlobal(a);
this._parent.globalToLocal(a);
return a.x;
};
MCP.set_y2 = function(v) {
var a = {x:this._xreg, y:this._yreg};
this.localToGlobal(a);
this._parent.globalToLocal(a);
this._y += v-a.y;
};
MCP.get_y2 = function() {
var a = {x:this._xreg, y:this._yreg};
this.localToGlobal(a);
this._parent.globalToLocal(a);
return a.y;
};
MCP.set_xscale2 = function(v) {
this.setPropRel("_xscale", v);
};
MCP.get_xscale2 = function() {
return this._xscale;
};
MCP.set_yscale2 = function(v) {
this.setPropRel("_yscale", v);
};
MCP.get_yscale2 = function() {
return this._yscale;
};
MCP.set_rotation2 = function(v) {
this.setPropRel("_rotation", v);
};
MCP.get_rotation2 = function() {
return this._rotation;
};
MCP.get_xmouse2 = function() {
return this._xmouse-this._xreg;
};
MCP.get_ymouse2 = function() {
return this._ymouse-this._yreg;
};
with (MCP) {
addProperty("_x2", get_x2, set_x2);
addProperty("_y2", get_y2, set_y2);
addProperty("_xscale2", get_xscale2, set_xscale2);
addProperty("_yscale2", get_yscale2, set_yscale2);
addProperty("_rotation2", get_rotation2, set_rotation2);
addProperty("_xmouse2", get_xmouse2, null);
addProperty("_ymouse2", get_ymouse2, null);
}
ASSetPropFlags(MCP, null, 1);
delete MCP;
//mc._xreg = 100;
//mc._yreg = 70;
//mc._rotation2 = 60;
//mc._x2;
//mc._y2 ;
//to position the movie clip according to the new reg point
//mc._xscale2;
//mc._yscale2 ;

kaka44
November 27th, 2007, 12:06 PM
The work is beaut (http://directory.7oll.com/)iful, thank you both contributed topic

outcast411
January 7th, 2008, 09:09 AM
Hi everyone,

I'm using the MovieClip registration Point class, when I Import the class to my code I get this error message "Error: A 'with' action failed because the specified object did not exist.".

Please take a look at my code and let me know what I'm doing wrong.
Here's the code:


import mx.controls.NumericStepper;
import com.darronschall.DynamicRegistration;
DynamicRegistration.initialize(naviloader3_mc);

_level0.naviloader3_mc.setRegistration(384,512);

#include "include/wallScript.as"
#include "include/leafScript.as"


var mclListener:Object = new Object();
var stageL:Object = new Object();





this.createEmptyMovieClip("naviloader_mc",3);
naviloader_mc.loadMovie("navi.swf");
naviloader_mc._y = Stage.height+-20;


this.createEmptyMovieClip("naviloader1_mc",5);
naviloader1_mc.loadMovie("Logo.swf");
naviloader1_mc._xscale = 50;
naviloader1_mc._yscale = 50;

this.createEmptyMovieClip("naviloader2_mc",2);
this.createEmptyMovieClip("naviloader3_mc",1);



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




stageL.onResize = function() {
naviloader3_mc._x =(Stage.width/2)-(naviloader3_mc._width/2);
naviloader3_mc._y =(Stage.height/2)-(naviloader3_mc._height/2);

};

Stage.addListener(stageL);


Thanks

mbrvar
January 28th, 2008, 11:22 AM
Here is the URL for proof http://www.darronschall.com/weblog/archives/000054.cfm
. check the comment section

Hello!
Have anybody use this class with transition tween class?
Thank you!