Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button Question

Status
Not open for further replies.

chazmania

Technical User
Jul 6, 2005
63
0
0
GB
by any chance does anyone know how to zoom into an image but clicking a button once?

In my Flash movie I have a map of europe and I would like one quick click of a button to zoom into particular parts of europe.

ie. click on the UK and there is a quick zoom that frames the UK.

Do you know how to do this, or have any info on this kind of event.

Thanks.
 
Here's very basic code I've just wrote; this will zoom in 4x and wherever clicked will be centred. Hope this is what you meant.
[tt]//
mcMap.onPress = function() {
var x:Number = this._xmouse;
var y:Number = this._ymouse;
this._x = this._x-x*2+this._width/2;
this._y = this._y-y*2+this._height/2;
this._xscale = 200;
this._yscale = 200;
};
//[/tt]

Kenneth Kawamoto
 
Thanks very much Kenneth.

But your going to laugh now! (cringe!)

Ive created a button but when I apply the code you've given nothing happens.

In the code, dont I have to put the name of the image im zoomin into somewhere?...(But I don't know where)

In the same way that I apply an action to a button (stop, play, on, etc) .......

is this the same way that I apply this code? (but in expert mode?)

Sorry for all the awful newbie questions, but its all a learning process for me i guess!

Thanks again!!

 
Sorry, I should have been clearer. The script is not for applying to a button but for placing on a timeline. Actually it is not for a button, but for a movieclip instance "mcMap".

By the way you said "expert mode" - do you mean you are using Flash 6? If so this won't work as I used AS2 syntax.

Here are the steps for Flash 6, this time with a "reset" button plus configurable zoom factor:

1. Create a movieclip with your map graphic in it.
2. Open the movieclip and move your map inside to (0, 0)
3. Place the movieclip on stage and name it "mcMap"
4. Create a "reset" button but make it as a simple 1 frame movieclip for now
5. Place the reset movieclip on stage and name it "mcBtn"
6. Create a new layer and name it "Actions"
7. In the Actions layer place the following script:

[tt]//
var initX = mcMap._x;
var initY = mcMap._y;
var factor = 4;
stop();
//
mcMap.onPress = function() {
var x = this._xmouse;
var y = this._ymouse;
this._x = this._x-x*factor+this._width/2;
this._y = this._y-y*factor+this._height/2;
this._xscale = factor*100;
this._yscale = factor*100;
};
//
mcBtn.onPress = function() {
mcMap._x = initX;
mcMap._y = initY;
mcMap._xscale = 100;
mcMap._yscale = 100;
};
//[/tt]

Remember, this is not to be applied to movieclips but to the frame. Make sure your Actions panel says "Actions - Frame".

I set the zoom factor to 4, meaning 4^2 = 16 x zoom. You can set it to any number - even to a number less than 1 or a negative number!

If you're using Flash 5 this won't work and you have to use button symbols - let me know if you are.

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top