incredibile!!!
ho creato proprio ieri una classe che fa al caso tuo!!!
allora, dovresti:
1) creare un filmato vuoto
2) mettici il tuo disegno e chiamalo 'montagne'
3) crei un simbolo con i tastini
ZOOM +
ZOOM -
ZOOM minimo
ZOOM massimo
ZOOM normale
poi fai tre frame:
'inout' dove ci sono tutti questi tasti
'out' dove manca il tasto ZOOM -
'in' dove manca il tasto ZOOM +
poi, per l'on(press) di ogni rispettivo tasto fai eseguire questi rispettivi metodi:
this.zoom_in();
this.zoom_out();
this.zoom_min();
this.zoom_max();
this.zoom_normal();
4) metti il tuo simbolo nel filmato, chiamandolo 'controller'. mi raccomando che sia concatenabile alla classe AS rmc
5) salvi il codice che ti do in un file rmc.as, lo metti nella stessa cartella del tuo filmato
6) vai nel tuo filmato e nel frame principale scrivi
_root.controller.control(_root.montagne);
_root.controller.zoom_set(50,200,10);
dove i tre parametri sono lo zoom minimo, quello massimo e la velocità di scalatura dello zoom
ECCO IL CODICE
codice:
class rmc extends MovieClip
{
var _tg:MovieClip;
var _maskname:String;
var _min:Number;
var _max:Number;
var _vel:Number;
var _nx:Number;
var _ny:Number;
var _nw:Number;
var _nh:Number;
var _azv:Number; // Actual Zoom Value
function control (_tg:MovieClip)
{
this._tg = _tg;
this._maskname = this._tg._name+"_machera";
// creo una maschera
_root.createEmptyMovieClip(this._maskname,_root.getNextHighestDepth());
// posiziono l'area e la maschera
_root[this._maskname]._x = this._nw = this._tg._x ;
_root[this._maskname]._y = this._nh = this._tg._y ;
// disegno la maschera e la applico
this.draw_mask();
this._tg.setMask(_root[this._maskname]);
}
function draw_mask()
{
with(_root[this._maskname]){
lineStyle(1,0x000000,100);
beginFill( 0xFF0000 );
moveTo(0 , 0);
lineTo(this._tg._width , 0);
lineTo(this._tg._width , this._tg._height);
lineTo(0 , this._tg._height);
lineTo(0 , 0);
endFill();
}
}
function zoom_set(_min:Number,_max:Number,_vel:Number)
{
this._min = _min;
this._max = _max;
this._vel = _vel;
this._azv = 100;
this._nw = this._tg._width;
this._nh = this._tg._height;
this._nx = this._tg._x;
this._ny = this._tg._y;
}
function zoom_in()
{
this.gotoAndStop('inout');
this._tg._width = (this._nw/100)*(this._azv+this._vel);
this._tg._height = (this._nh/100)*(this._azv+this._vel);
if (this._azv+this._vel >= this._max)
{
this._tg._width = (this._nw/100)*(this._max);
this._tg._height = (this._nh/100)*(this._max);
this._azv = this._max;
this.gotoAndStop('out');
}
else
{
this._azv +=this._vel;
}
if (this._azv > 100) this.start_drag();
}
function zoom_out()
{
this.gotoAndStop('inout');
this._tg._width = (this._nw/100)*(this._azv-this._vel);
this._tg._height = (this._nh/100)*(this._azv-this._vel);
if (this._azv-this._vel <= this._min)
{
this._tg._width = (this._nw/100)*(this._min);
this._tg._height = (this._nh/100)*(this._min);
this._azv = this._min;
this.gotoAndStop('in');
}
else
{
this._azv -=this._vel;
var t = this._tg;
if (t._x + t._width < this._nx + this._nw) t._x = this._nx + this._nw - t._width ;
if (t._y + t._height < this._ny + this._nh) t._y = this._ny + this._nh - t._height ;
if (t._x > this._nx ) t._x = this._nx ;
if (t._y > this._ny ) t._y = this._ny ;
}
if (this._azv <= 100)
{
this.stop_drag();
this._tg._x = this._nx ;
this._tg._y = this._ny ;
}
}
function zoom_min()
{
this._tg._width = (this._nw/100)*(this._min);
this._tg._height = (this._nh/100)*(this._min);
this.center();
this._azv = this._min;
stop_drag();
this.gotoAndStop('in');
}
function zoom_max()
{
this._tg._width = (this._nw/100)*(this._max);
this._tg._height = (this._nh/100)*(this._max);
this.center();
this._azv = this._max;
start_drag();
this.gotoAndStop('out');
}
function zoom_normal()
{
this._tg._width = this._nw;
this._tg._height = this._nh;
this.center();
this._azv = 100;
this.gotoAndStop('inout');
}
function center()
{
this._tg._x = (2*this._nx + this._nw - this._tg._width)/2;
this._tg._y = (2*this._ny + this._nh - this._tg._height)/2;
}
function start_drag()
{
var a = this._nx + this._nw - this._tg._width;
var b = this._ny + this._nh - this._tg._height;
var c = this._nx;
var d = this._ny;
this._tg.onPress = function () {
this.startDrag( false, a , b , c , d );
}
this._tg.onRelease = function () {
stopDrag();
}
}
function stop_drag()
{
this._tg.onPress = this._tg.onRelease = function () {}
}
}