Codice PHP:
#initclip 2
MyMenuClass = function () {
this.init();
};
MyMenuClass.prototype = new MovieClip();
Object.registerClass("Menu", MyMenuClass);
MyMenuClass.prototype.init = function() {
this.buttonLabels = [];
this.buttonFunctions = [];
this.buttonArguments = [];
this.buttonTargets = [];
this._w = this._width;
this._h = (this._height<16) ? 16 : this._height;
this._xscale = 100;
this._yscale = 100;
this.xmlData = new XML();
this.xmlData.ignoreWhite = true;
this.xmlData.load(this.xmlFile);
this.xmlData._p = this;
this.xmlData.onLoad = function(ok) {
if (ok) {
this._p.readXML(this._p.xmlData);
this._p.drawMenu();
delete this._p.xmlData;
}
};
};
MyMenuClass.prototype.drawMenu = function() {
this.createEmptyMovieClip("menuHitArea", 0);
this.menuHitArea._visible = false;
this.resetHitArea();
this.hitArea = this.menuHitArea;
this.createEmptyMovieClip("menuBackground", this.buttonLabels.length+1);
with (this.menuBackground) {
beginFill(_parent.fillColor, 100);
moveTo(0, 0);
lineStyle(1, _parent.borderColor, 100);
lineTo(_parent._w, 0);
lineTo(_parent._w, _parent._h);
lineTo(0, _parent._h);
endFill();
}
var format = new TextFormat("nitida_FFF Galaxy", 8, this.menuTextColor, true, null, null, null, null, "center");
this.attachMovie("Label", "menuLabel", this.buttonLabels.length+2);
this.menuLabel._y = (this._h-18)/2;
this.menuLabel.init();
this.menuLabel.setMyLabelFormat(format);
//this.menuLabel.setMyLabel(this.label);
this.menuLabel.setMyLabel(titolomenu);
this.onRollOver = function() {
this.drawSubMenu();
};
this.onRollOut = function() {
this.killSubMenu();
};
this.onDragOut = function() {
this.killSubMenu();
};
};
MyMenuClass.prototype.killSubMenu = function() {
for (var i = 0; i<this.buttonLabels.length; i++) {
this["Button"+i].removeMovieClip();
}
this.resetHitArea();
};
MyMenuClass.prototype.resetHitArea = function() {
with (this.menuHitArea) {
clear();
beginFill(0x000000, 100);
moveTo(0, 0);
lineStyle(0, 0x000000, 100);
lineTo(_parent._w, 0);
lineTo(_parent._w, _parent._h);
lineTo(0, _parent._h);
endFill();
}
};
MyMenuClass.prototype.resizeHitArea = function(pt0, pt1, pt2, pt3, pt4, pt5) {
with (this.menuHitArea) {
beginFill(0x000000, 100);
moveTo(pt0[0], pt0[1]);
lineStyle(0, 0x000000, 100);
lineTo(pt1[0], pt1[1]);
lineTo(pt2[0], pt2[1]);
lineTo(pt3[0], pt3[1]);
lineTo(pt4[0], pt4[1]);
lineTo(pt5[0], pt5[1]);
lineTo(pt0[0], pt0[1]);
endFill();
}
};
MyMenuClass.prototype.drawSubMenu = function() {
switch (this.open) {
case "giù_centro" :
var x0 = 0;
var y0 = 0;
var x1 = this._w;
var y1 = 0;
var x2 = x1;
var y2 = (this.buttonLabels.length+1)*this.menuBackground._height-1;
var x3 = 0;
var y3 = y2;
var x4 = 0, y4 = 0, x5 = 0, y5 = 0;
break;
}
this.resizeHitArea([x0, y0], [x1, y1], [x2, y2], [x3, y3], [x4, y4], [x5, y5]);
for (var i = 0; i<this.buttonLabels.length; i++) {
with (this.attachMovie("Button", "Button"+i, this.buttonLabels.length-i)) {
init(this.buttonTargets[i], this.buttonFunctions[i], this.buttonArguments[i]);
_x = 0;
_y = 0;
setButtonLabel(this.buttonLabels[i]);
}
}
this.menuAnimation();
};
MyMenuClass.prototype.menuAnimation = function() {
var gap = (this.menuBackground._height+this.menuBackground._height)/4;
switch (this.open) {
case "giù_centro" :
this.onEnterFrame = function() {
for (var i = 0; i<this.buttonLabels.length; i++) {
this["Button"+i]._y = (this["Button"+i]._y<(this.menuBackground._height+(this.menuBackground._height)*i)) ? this["Button"+i]._y+gap : this.menuBackground._height+(this.menuBackground._height)*i;
this["Button"+i].setActive((this["Button"+i]._y == this.menuBackground._height+(this.menuBackground._height)*i) ? true : false);
}
};
break;
}
};
MyMenuClass.prototype.readXML = function(xml) {
var Nodes = xml.childNodes[0].childNodes;
titolomenu = xml.childNodes[0].attributes.nome;
for (var i = 0; i<Nodes.length; i++) {
this.buttonLabels.push(Nodes[i].attributes.etichetta);
this.buttonTargets.push(Nodes[i].attributes.target);
this.buttonFunctions.push(Nodes[i].attributes.funzione);
this.buttonArguments.push(Nodes[i].attributes.parametri.split(","));
}
};
#endinitclip
area_anteprima._visible = false;