Ajd da nastavimo gde smo stali sa proslim postom ...
Napravi MC u library i daj mu ime kakvo hoces,
u properties-u kao AS 2.0 klasu stavi klasu pitanje.
Prevuci MC iz library-a na stage, daj mu ime kakvo zelis.
na _leve0 timeline-u dodaj sledece
Code:
this.onLoad = function() {
imeMCaKojeSiDao.init();
}
to ce obezbediti da se kod pocne izvrsavati kad se sve ucita i inicijalizuje
napravi AS 2.0 class file i u njega ubaci vec poznatu nam klasu
Code:
import mx.utils.Delegate;
class pitanje extends MovieClip {
// declare vars needed for class
private var i:Number;
private var my_ar:Array;
private var xmlData:XML;
private var kvadrat:MovieClip;
// initialize the vars, set the XML Object to ignore the white space,
// set the function that will be called for the XML onLoad event
function pitanje() {
my_ar = new Array();
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = Delegate.create(this,goto);
}
//initialize function, it will create the MC and draw a square in it
// also it will start the loading of the XML
public function init(){
kvadrat = this.createEmptyMovieClip("kvadrat", this.getNextHighestDepth());
kvadrat.lineStyle(3, 0x000099, 100);
kvadrat.lineTo(25,0);
kvadrat.lineTo(25,25);
kvadrat.lineTo(0,25);
kvadrat.lineTo(0,0);
kvadrat._visible = false;
loadXML();
// if you call array function here you will get nothing back,
// since the loading has been started, it may not have completed yet
//array();
}
// start the loading of the xml file
private function loadXML() {
trace("loadXML");
xmlData.load("pitanje.xml");
}
//function that is called when the xml file is loaded,
// param success will be true for successfull loading of the xml file
function goto(success) {
if (success) {
// trace the whole xml file
trace(xmlData)
// set the root node
var rootNode:XMLNode = xmlData.firstChild;
// go through all the childnodes in the root node
for (i=0; i<rootNode.childNodes.length; i++) {
//var my_ar = new Array();
// and add their text values to the array
my_ar.push(rootNode.childNodes[i].firstChild);
// trace the current content of the my_ar array
//trace("my_ar = " + my_ar);
kvadrat.duplicateMovieClip("kvadrat"+i,this.getNextHighestDepth());
this["kvadrat"+i]._x = (this["kvadrat"+i]._width + 5) * i
}
// when you call the function here it will list the contents of
// the array, because the load has been completed and the xml
// has been parsed
array();
} else {
trace("crap")
}
}
// list the contents of the my_ar array
private function array() {
trace("array = " + my_ar)
}
}
taj fajl snimi kao pitanje.as
i to je to...
Sad dalje bi bilo lepo da radis sam........