-
Resizing from center
Hi all (Happy New Year),
I'm currently running a script that successfully resizes an imported image upon rollover using the tween class. The only issue i have is the registration point. How do i move the registration point to the center? At the moment it is resizing from the top left (0,0).
Code:
import mx.transitions.Tween;
import mx.transitions.easing.*;
import flash.display.*;
var srcImg1 = "http://www.myserver.com/Red.png";
var srcImg2 = "http://www.myserver.com/Silver.png";
var srcImg3 = "http://www.myserver.com/Black.png";
var mainHolder = this.createEmptyMovieClip("main", this.getNextHighestDepth());
var original = mainHolder.createEmptyMovieClip("original", mainHolder.getNextHighestDepth());
var smooth = mainHolder.createEmptyMovieClip("smooth", mainHolder.getNextHighestDepth());
var mclListener:Object = new Object();
mclListener.onLoadInit = function() {
var w = original._width;
var h = original._height;
var bmpData1:BitmapData = new BitmapData(w, h, true, 0x000000); //true and 0 color allows for transparency
bmpData1.draw(original);
smooth.attachBitmap(bmpData1, 2, "auto", true); //true for SMOOTHING, ;)
//smooth._alpha=50;
smooth._width = 194;
smooth._height = 125;
original.removeMovieClip();
};
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
image_mcl.loadClip(srcImg1, original);
main._rotation = 0;
main._x = 50;
main._y = 70;
main.onRollOver = function() {
main.swapDepths(getNextHighestDepth());
var myTween_mp:Tween = new Tween(this, "_xscale", Back.easeOut, 100, 150, 1, true);
var myTween_mp:Tween = new Tween(this, "_yscale", Back.easeOut, 100, 150, 1, true);
var myTween_mp:Tween = new Tween(myTxt, "_yscale", Back.easeOut, 100, 200, 1, true);
};
main.onRollOut = function() {
var myTween_mp:Tween = new Tween(this, "_xscale", Back.easeOut, 150, 100, 1, true);
var myTween_mp:Tween = new Tween(this, "_yscale", Back.easeOut, 150, 100, 1, true);
var myTween_mp:Tween = new Tween(myTxt, "_yscale", Back.easeOut, 200, 100, 1, true);
};
main.onPress = function() {
getURL("http://www.google.com","_blank");
};
this.createTextField("myTxt", getNextHighestDepth(), 170, 50, 100, 20);
myTxt.autoSize = "left";
myTxt.multiline = true;
myTxt.html = true;
myTxt.htmlText = "H3";
//<br><font size='14' color='#999999' face='Arial'>Out of Stock</font>
myformat = new TextFormat();
myformat.font = "Trebuchet MS";
myformat.bold = true;
myformat.size = 14;
myformat.textColor = 0x000000;
myTxt.setTextFormat(myformat);
Cheers,
micmac
Last edited by micmac; 01-01-2008 at 01:11 AM.
Reason: added code tags
!.....................................COMING SOON
-
add this to the actions in frame 1 of the main timeline, and tween "width" and "height" instead of "_width" and "_height"
PHP Code:
MovieClip.prototype.addProperty("height", function () {
return this._height;
}, function (b) {
this._y -= ((b |= 0)-this._height)/2;
this._height = b;
});
MovieClip.prototype.addProperty("width", function () {
return this._width;
}, function (b) {
this._x -= ((b |= 0)-this._width)/2;
this._width = b;
});
-
Thanks for the reply.
Almost there. I added the above code to the first frame and changed the tween to "width" and "height" but upon rollover the image resizes to the new centered reg. point however the image now appears squashed. Any ideas as to why this might be?
Cheers,
micmac
!.....................................COMING SOON
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|