sapete ragazzi alle volte il forum di AS mi sembra un po' arido. pero' la comunità rimane uno strumento preziosissimo che vorrei arricchire. così ho fatto questa classe (e poi magari in giro c'e' roba meglio eheheheh)
chissà che non possa essere utile a qualcuno o che si possa migliorare e soprattutto ragazzi, diamoci da fare! non dobbiamo essere tirchi di risposte! il dialogo qui dentro ci fa comodo a tutti, forza forza forza ...![]()
-------------------------------------
gli oggetti della classe AREA sono dei contenitori dove movieclip possono essere impilati, in senso verticale od orizzontale. siccome le aree sono di dimensione definita, viene gestito anche lo scroll per poter visualizzare tutto il contenuto dell'area.
-------------------------------------
per iniziare (come prova) occorre:
* creare un clip filmato consistente in un semplice rettangolino (grafica a vostro piacimento) e chiamarlo 'scroll_btn', attivarne l'esportazione per AS
* creare degli elementi grafici rettangolari grandi 120X30
fatene uno giallo, uno verde e chiamateli 'uno' e 'due'
* copiate la classe dentro un file di nome area.as e mettelo nella stessa directory del filmato che andrete a creare
-------------------------------------
fate un nuovo filmato, salvatelo nella cartella sopracitata, e scrivete nel frame principale:
miarea=new area(_root,"menu",40,40,300,40,1,5);
opzione1 = miarea.add_inside("uno");
miarea.add_inside("due");
in sostanza avete creato un'area, e avete aggiunto a questa i due movieclip. potete continuare ad aggiungerli. se superate le dimensioni dell'area, sarà gestito lo scroll.
ecco cosa significano i parametri:
_root e' dove viene attaccata l'area
"menu" e' il nome che gli daro'
40 posizione x
40 posizione y
300 dimensione x
40 dimensione y
1 area in senso orizzontale (0 e' verticale)
5 spazio tra i movieclip messi dentro
come metodi abbiamo:
add_inside (<nome del movieclip>) - mette dentro un movieclip; restituisce l'id dell'oggetto
clear_insides () - cancella il contenuto
del_inside (<id dell'oggetto>) - cancella un movieclip
-------------------------------------
fatemi sapere chene pensate!
![]()
codice:class area { /************************************************************* PARAMETRI E COSTRUTTORE **************************************************************/ var _type:Number; var _spacing:Number; var _anchor:Object; var _nome:String; var _insides:Array; var _posx:Number; var _posy:Number; var _dimx:Number; var _dimy:Number; var _fully:Number; var _scroll_amount:Number; function area (_anchor:Object, _nome:String, _posx:Number, _posy:Number, _dimx:Number, _dimy:Number, _type:Number, _spacing:Number) { // inizializzo la mia area this._insides = new Array(); this._type = _type; this._spacing = _spacing; this._anchor = _anchor; this._nome = _nome; this._dimx = _dimx; this._dimy = _dimy; this._posx = _posx; this._posy = _posy; this._fully = 0; this._scroll_amount = (_type==1)?40:10; // creo l'area, la maschera e la function _root[_anchor].createEmptyMovieClip(_nome,_root[_anchor].getNextHighestDepth()); _root[_anchor].createEmptyMovieClip(_nome+"_maschera",_root[_anchor].getNextHighestDepth()); _root[_anchor].createEmptyMovieClip(_nome+"_function",_root[_anchor].getNextHighestDepth()); // posiziono l'area e la maschera _anchor[_nome]._x = _anchor[_nome+"_maschera"]._x = _anchor[_nome+"_function"]._x = _posx; _anchor[_nome]._y = _anchor[_nome+"_maschera"]._y = _anchor[_nome+"_function"]._y = _posy; // disegno la maschera e la applico this.draw_mask(); _anchor[_nome].setMask(_anchor[_nome+"_maschera"]); } function draw_mask() { with(this._anchor[this._nome+"_maschera"]){ lineStyle(1,0x000000,100); beginFill( 0xFF0000 ); moveTo(0,0); lineTo(this._dimx,0); lineTo(this._dimx,this._dimy); lineTo(0,this._dimy); lineTo(0,0); endFill(); } } /************************************************************* ISTANZE *************************************************************/ function destroy () { this._anchor[this._nome].removeMovieClip(); } /************************************************************* INSIDES *************************************************************/ function add_inside (idObj:String) { // individuo la mia area, ricavo l'id e il nome del mio inside var tg = _anchor[this._nome]; var id = this._insides.length; var nm = "ins_"+id; // attacco l'inside tg.attachMovie(idObj, nm, tg.getNextHighestDepth()); // registro l'inside dentro l'array dell'area this._insides[id]=nm; // posiziono correttamente l'inside switch (this._type) { case 0: // VERTICALE tg[nm]._x = (this._dimx-tg[nm]._width)/2 tg[nm]._y = this._fully+this._spacing; this._fully += tg[nm]._height+this._spacing; break; case 1: // ORIZZONTALE tg[nm]._x = this._fully+this._spacing; tg[nm]._y = (this._dimy-tg[nm]._height)/2 this._fully += tg[nm]._width+this._spacing; break; } // controllo ed eventuale inserimento del sistema di scrolling if (this._fully>this[((this._type==1)?'_dimx':'_dimy')] and !this._anchor[this._nome+"_function"]["btn_"+((this._type==1)?'1':'2')]) { scroll_btn_add (((this._type==0)?2:1)); } // ritorna l'inside come oggetto return tg[nm]; } function del_inside (obj:Object) { removeMovieClip(obj); } function clear_insides () { for(var scan in this._insides) { removeMovieClip(_root[this._anchor][this._nome][this._insides[scan]]); } } /************************************************************ SCROLL ************************************************************/ function scroll_go (where:Number) { // punto all'area var tg = this._anchor[this._nome]; // effettuo lo scroll switch (where) { case 0: tg._y += this._scroll_amount; if (tg._y > this._posy) { scroll_btn_del (where); tg._y = this._posy; } break; case 1: tg._x -= this._scroll_amount; if (Math.abs(tg._x)>(tg._width-this._dimx)-this._posx+this._scroll_amount) { scroll_btn_del (where) tg._x = tg._x + this._posx; } break; case 2: tg._y -= this._scroll_amount; if (tg._y+this._fully < this._posy + this._dimy) { scroll_btn_del (where) tg._y < this._posy + this._dimy - this._fully } break; case 3: tg._x += this._scroll_amount; if (tg._x>0) { scroll_btn_del (where); tg._x = this._posx; } break; } // aggiungo il tasto complementare var comp = (where+2)%4; if (!this._anchor[this._nome+"_function"]["btn_"+comp]) scroll_btn_add(comp); } function scroll_btn_add (where:Number) { // imposto l'altezza del mio tasto var spessore = (this[(where==0 or where==2)?'_dimy':'_dimx']/100)*7 // miro alla function var tg = this._anchor[this._nome+"_function"]; // attacco il tasto all'area tg.attachMovie("scroll_btn","btn_"+where,tg.getNextHighestDepth()); // posiziono e dimensiono il tasto with(tg["btn_"+where]){ switch (where){ case 0: _y = 2; _x = 2; _width = this._dimx-4; _height = spessore; break; case 1: _y = 2; _x = this._dimx-spessore-2; _width = spessore; _height = this._dimy-4; break; case 2: _y = this._dimy-spessore-2; _x = 2; _width = this._dimx-4; _height = spessore; break; case 3: _y = 2; _x = 2; _width = spessore ; _height = this._dimy-4; break; } // assegno al tasto la funzione di scroll var reference=this; tg["btn_"+where].onEnterFrame = function () { if (hitTest(_root._xmouse,_root._ymouse,true)) reference.scroll_go(where); } } } function scroll_btn_del (where:Number) { removeMovieClip(this._anchor[this._nome+"_function"]["btn_"+where]); } }

Rispondi quotando
