//
import mx.transitions.Tween;
//
function XMLinit(XMLpath) {
chordXML = new XML();
chordXML.ignoreWhite = true;
chordXML.onLoad = function(success) {
if (success) {
//trace(chordXML);
//showSelection(0);
CHORDInit();
}
};
chordXML.load(XMLpath);
//
// setting event
figureEman.onPress = function() {
showSelection(0);
};
figureEllen.onPress = function() {
showSelection(1);
};
//
but100.onPress = function() {
strummingTime = 100;
};
but200.onPress = function() {
strummingTime = 200;
};
but300.onPress = function() {
strummingTime = 300;
};
but400.onPress = function() {
strummingTime = 400;
};
//
chordTextMCnormal._visible = false;
chordTextMCzoom._visible = false;
chordTextMCthumb._visible = true;
}
function showSelection(nodeIndex) {
chordThumbLayer = this["chordTextMCthumb"];//this.createEmptyMovieClip("chordTuhmbLayer", 0);
thumbOffsetX = 300;
thumbOffsetY = 85;
var column = 6;
//
currentNodeIndex = nodeIndex;
chordTotal = chordXML.childNodes[0].childNodes[currentNodeIndex].childNodes.length;
// show title text
var tmpTextTitle = chordXML.childNodes[0].childNodes[currentNodeIndex].attributes.txtTitle;
chordTextMCthumb.txtObjTitle.text = tmpTextTitle;
//
for (i=0; i<chordTotal; i++) {
chordObj = chordThumbLayer.attachMovie("chordButtonUnit", "chordButtonUnit"+i, i);
var chordNameTmp = chordXML.childNodes[0].childNodes[currentNodeIndex].childNodes[i].attributes.chordName;
chordObj.txtObj0.text = chordNameTmp.charAt(0);
chordObj.txtObj1.text = chordNameTmp.substr(1, chordNameTmp.length-1);
chordObj.chordTab = chordXML.childNodes[0].childNodes[currentNodeIndex].childNodes[i].attributes.chordTab;
chordObj.barChordBoolean = chordXML.childNodes[0].childNodes[currentNodeIndex].childNodes[i].attributes.barChordBoolean;
// these leads to the next function showChord(thumbParentIndex, thumbChordIndex)
chordObj.parentIndex = currentNodeIndex;
chordObj.chordIndex = i;
// event
chordObj.butObj.onPress = function() {
showChord(this._parent.parentIndex,this._parent.chordIndex);
formChord(this._parent.chordTab,this._parent.barChordBoolean);
};
// physical properties
chordObj._x = (chordObj._width+5)*(i%column)+thumbOffsetX;
chordObj._y = (chordObj._height+5)*(i-i%column)/column+thumbOffsetY;
}
chordThumbLayerAlphaTween = new Tween(chordThumbLayer, "_alpha", mx.transitions.easing.Regular.easeOut, 0, 100, .75, true);
// character Scale Setting
if (nodeIndex == 0) {
// the character eman
emanScaleXTween = new Tween(figureEman, "_xscale", mx.transitions.easing.Regular.easeOut, figureEman._xscale, figureScaleMax, 1, true);
emanScaleYTween = new Tween(figureEman, "_yscale", mx.transitions.easing.Regular.easeOut, figureEman._yscale, figureScaleMax, 1, true);
// the character ellen
ellenScaleXTween = new Tween(figureEllen, "_xscale", mx.transitions.easing.Regular.easeOut, figureEllen._xscale, figureScaleMin, 1, true);
ellenScaleYTween = new Tween(figureEllen, "_yscale", mx.transitions.easing.Regular.easeOut, figureEllen._yscale, figureScaleMin, 1, true);
} else if (nodeIndex == 1) {
// the character eman
emanScaleXTween = new Tween(figureEman, "_xscale", mx.transitions.easing.Regular.easeOut, figureEman._xscale, figureScaleMin, 1, true);
emanScaleYTween = new Tween(figureEman, "_yscale", mx.transitions.easing.Regular.easeOut, figureEman._yscale, figureScaleMin, 1, true);
// the character ellen
ellenScaleXTween = new Tween(figureEllen, "_xscale", mx.transitions.easing.Regular.easeOut, figureEllen._xscale, figureScaleMax, 1, true);
ellenScaleYTween = new Tween(figureEllen, "_yscale", mx.transitions.easing.Regular.easeOut, figureEllen._yscale, figureScaleMax, 1, true);
}
//
showChord(currentNodeIndex,0);
}
function CHORDInit() {
// play chord setting
stringTotal = 6;
fingerTotal = 6;
strummingTime = 400;
// gtr obj setting
gtrDefaultMinS = 30;
gtrDefaultMinX = 302;
gtrDefaultMinY = 378;
gtrDefaultMaxX = 302;
gtrDefaultMaxY = 333;
gtrDefaultMaxS = 100;
// character setting
figureScaleMin = 50;
figureScaleMax = 100;
figureScaleIdle = 75;
//
gtrLineArray = [168, 136, 103, 72, 38, 6];
for (k=0; k<fingerTotal; k++) {
//
gtrObj = this["guitarMC"];
//
fingerObj = gtrObj.attachMovie("guitarFingerMarkUnit", "finger"+k, k);
fingerObj._x = 0;
fingerObj._y = gtrLineArray[k];
fingerObj.gotoAndStop(3);
// trace("fingerObj._x : "+fingerObj._x);
//
lineObj = gtrObj["line"+k];
lineObj.gotoAndStop(1);
}
gtrObj._xscale = gtrObj._yscale=gtrDefaultMinS;
// clear text in display
chordTextMCnormal.txtObjChord.text = "";
chordTextMCnormal.txtObjChordFamily.text = "";
chordTextMCnormal.txtObjMood.text = "";
chordTextMCnormal.txtObjDetail.text = "";
chordTextMCnormal.txtObjTitle.text = "";
chordTextMCnormal.txtObjChord.autoSize = "right";
//
zoomMode = "normal";
//
figureEman._xscale = figureEman._yscale=figureEllen._xscale=figureEllen._yscale=figureScaleIdle;
}
function zoomIn(chordTabCal) {
zoomMode = "zoom";
//
chordTextMCnormal._visible = false;
chordTextMCzoom._visible = true;
//
var compareArray = chordTabCal.split("");
var compareMin:Number = 0;
var compareCache:Number = 0;
for (u=0; u<compareArray.length; u++) {
if (compareArray[u]<=compareCache) {
compareMin = compareArray[u];
}
compareCache = compareArray[u];
}
//
gtrDefaultMaxX = gtrDefaultMinX-compareMin*100;
gtrObjScaleXTween = new Tween(gtrObj, "_xscale", mx.transitions.easing.Regular.easeOut, gtrObj._xscale, gtrDefaultMaxS, 1, true);
gtrObjScaleYTween = new Tween(gtrObj, "_yscale", mx.transitions.easing.Regular.easeOut, gtrObj._yscale, gtrDefaultMaxS, 1, true);
gtrObjXTween = new Tween(gtrObj, "_x", mx.transitions.easing.Regular.easeOut, gtrObj._x, gtrDefaultMaxX, 1, true);
gtrObjYTween = new Tween(gtrObj, "_y", mx.transitions.easing.Regular.easeOut, gtrObj._y, gtrDefaultMaxY, 1, true);
// character
figureEmanYTween = new Tween(figureEman, "_y", mx.transitions.easing.Regular.easeOut, figureEman._y, gtrDefaultMaxY, 1, true);
figureEllenYTween = new Tween(figureEllen, "_y", mx.transitions.easing.Regular.easeOut, figureEllen._y, gtrDefaultMaxY, 1, true);
//
}
function zoomOut() {
zoomMode = "normal";
//
chordTextMCnormal._visible = true;
chordTextMCzoom._visible = false;
gtrObjScaleXTween = new Tween(gtrObj, "_xscale", mx.transitions.easing.Regular.easeOut, gtrObj._xscale, gtrDefaultMinS, 1, true);
gtrObjScaleYTween = new Tween(gtrObj, "_yscale", mx.transitions.easing.Regular.easeOut, gtrObj._yscale, gtrDefaultMinS, 1, true);
gtrObjXTween = new Tween(gtrObj, "_x", mx.transitions.easing.Regular.easeOut, gtrObj._x, gtrDefaultMinX, 1, true);
gtrObjYTween = new Tween(gtrObj, "_y", mx.transitions.easing.Regular.easeOut, gtrObj._y, gtrDefaultMinY, 1, true);
// character
figureEmanYTween = new Tween(figureEman, "_y", mx.transitions.easing.Regular.easeOut, figureEman._y, gtrDefaultMinY, 1, true);
figureEllenYTween = new Tween(figureEllen, "_y", mx.transitions.easing.Regular.easeOut, figureEllen._y, gtrDefaultMinY, 1, true);
}
function showChord(thumbParentIndex, thumbChordIndex) {
// for the zoomNormal Interface
// display for the zoomNormal Interface
chordTextMCnormal.txtObjChordFamily.text = "";
chordTextMCnormal.txtObjChordFamily._width = 0;
chordTextMCnormal.txtObjChordFamily.wordWrap = false;
chordTextMCnormal.txtObjChordFamily.autoSize = "left";
//
var tmpChordName = chordXML.childNodes[0].childNodes[thumbParentIndex].childNodes[thumbChordIndex].attributes.chordName;
var tmpChordTab = chordXML.childNodes[0].childNodes[thumbParentIndex].childNodes[thumbChordIndex].attributes.chordTab;
var tmpBarChordBoolean = chordXML.childNodes[0].childNodes[thumbParentIndex].childNodes[thumbChordIndex].attributes.barChordBoolean;
var tmpChordMood = chordXML.childNodes[0].childNodes[thumbParentIndex].childNodes[thumbChordIndex].childNodes[0];
var tmpChordText = chordXML.childNodes[0].childNodes[thumbParentIndex].childNodes[thumbChordIndex].childNodes[1];
//display's physical properties for the zoomNormal Interface
chordTextMCnormal.txtObjChord.text = tmpChordName.charAt(0);
chordTextMCnormal.txtObjChordFamily.text = tmpChordName.substr(1, tmpChordName.length-1);
chordTextMCnormal.txtObjMood.text = tmpChordMood;
chordTextMCnormal.txtObjDetail.text = tmpChordText;
//
chordTextMCnormal.txtObjChordFamily._x = 280-chordTextMCnormal.txtObjChordFamily._width;
chordTextMCnormal.txtObjChord._x = chordTextMCnormal.txtObjChordFamily._x-chordTextMCnormal.txtObjChord._width-10;
//
trace("var tmpChordTab : "+tmpChordTab);
// playChord(tmpChordTab);
chordTextMCnormal.butPlayIt.onPress = function() {
playChord(tmpChordTab);
trace("chordTextMCnormal.butPlayIt.onPress : tmpChordTab : "+tmpChordTab);
};
chordTextMCnormal.butZoomIn.onPress = function() {
zoomIn(tmpChordTab);
};
//
if (zoomMode == "normal") {
zoomOut();
} else {
zoomIn(tmpChordTab);
}
//
// for the zoomIn interface
// display
chordTextMCzoom.txtObjChord.text = tmpChordName;
//event
chordTextMCzoom.butPlayIt.onPress = function() {
playChord(tmpChordTab);
trace("chordTextMCzoom.butPlayIt.onPress : tmpChordTab : "+tmpChordTab);
};
chordTextMCzoom.butZoomOut.onPress = function() {
zoomOut();
};
}
function playChord(chordString) {
trace(chordString);
// kills all sound before a new start
soundObj.stop();
//
stringCount = 0;
//
// clear all happened
clearInterval(interval_PlayString);
//
chord_string = chordString;
// spilt the chord
chord_array = chord_string.split("");
// setting constant
chord_addictive = [5, 5, 5, 4, 5, 0];
//
true_chord_note = new Array();
//
for (i=0; i<6; i++) {
var tmp_val = Number(chord_array[i]);
//
for (j=0; j<i; j++) {
tmp_val += chord_addictive[j];
}
if (chord_array[i] == "x") {
tmp_val = 10000;
}
//
true_chord_note.push(tmp_val);
}
//
//trace(chord_array);
//trace(true_chord_note);
//trace("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
//
interval_PlayString = setInterval(playString, strummingTime);
//
chordObj = this.createEmptyMovieClip("stringMC", 1);
soundObj = new Sound(chordObj);
soundObj.attachSound("guitarNOte");
}
function playString() {
soundObj.stop();
//
timeOffset = true_chord_note[stringCount]/2;
//
soundObj.start(timeOffset,1);
//
// redString
for (t=0; t<fingerTotal; t++) {
lineObj = gtrObj["line"+t];
if (t == stringCount) {
if (true_chord_note[stringCount] != 10000) {
lineObj.gotoAndStop(2);
} else {
// "X" in chordTab
lineObj.gotoAndStop(1);
}
} else {
lineObj.gotoAndStop(1);
}
}
// figure head move
if (currentNodeIndex == 0) {
figureObj = figureEman;
} else {
figureObj = figureEllen;
}
trace("figureObj._name : "+figureObj._name+" & currentNodeIndex : "+currentNodeIndex);
if (stringCount<stringTotal) {
figureObj.head._rotation = ((random(2)*2)-1)*random(20);
}
//
//
stringCount++;
//
if (stringCount>=stringTotal+1) {
stringCount = 0;
soundObj.stop();
//
for (t=0; t<fingerTotal; t++) {
lineObj = this["guitarMC"]["line"+t];
lineObj.gotoAndStop(1);
}
clearInterval(interval_PlayString);
}
}
function formChord(tab, barOrNot) {
gtrObj = this["guitarMC"];
fingerTotal = 6;
gtrLineArray = [168, 136, 103, 72, 38, 6];
//
chordTab = tab;
// trace("tab : "+tab+" & barOrNot : "+barOrNot);
// spilt the chord
chordTabArray = chordTab.split("");
for (k=0; k<fingerTotal; k++) {
//
fingerObj = gtrObj["finger"+k];
//
//
if (barOrNot == "true") {
// for bar chord's case
if (k == 0) {
fingerObj.gotoAndStop(2);
fingerObj.xPos = Number(chordTabArray[k])*100-50;
} else if (Number(chordTabArray[k]) == Number(chordTabArray[0])) {
//everyFinger same as the 1st BarFinger will go blank
fingerObj.gotoAndStop(3);
} else {
fingerObj.gotoAndStop(1);
fingerObj.xPos = Number(chordTabArray[k])*100-50;
}
} else if (barOrNot == "false") {
trace("no bar chord");
// if no bar chord . hide all [k] = 0
if (Number(chordTabArray[k]) == 0) {
// empty string go blank
fingerObj.gotoAndStop(3);
fingerObj.xPos = Number(chordTabArray[k])*100-50;
} else if (chordTabArray[k] == "x") {
// name as "X" no need to move
fingerObj.gotoAndStop(4);
fingerObj.xPos = 50;
} else {
// the rest outcome... !=0 && also not as "x"
fingerObj.gotoAndStop(1);
fingerObj.xPos = Number(chordTabArray[k])*100-50;
}
}
var myTweenX:Tween = new Tween(fingerObj, "_x", mx.transitions.easing.Regular.easeOut, fingerObj._x, fingerObj.xPos, .5, true);
}
}
//
//
//
//
XMLinit("chord.xml");
