Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

private function()

[es] :: Flash :: private function()

[ Pregleda: 2160 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

sekvoja

Član broj: 91239
Poruke: 269
*.ptt.yu.



Profil

icon private function()24.04.2006. u 17:49 - pre 219 meseci
U funkciji loadXML() postoji trace koji vraca sve elemente xml fajla i on radi. Kada njega komentujem, a odkomentujem trace u f-ji array(), dobijam error "There is no property with the name 'my_ar." Problem je sledeci: Kako da iz f-je array() pristupim promenljivoj my_ar koja je definisana u f-ji loadXML().

class pitanje extends MovieClip {

var i:Number;

function pitanje() {
loadXML();
array();
}

private function loadXML() {
var xmlData:XML;
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = function(ok) {
if (ok) {
goto(xmlData);
}
};
xmlData.load("pitanje.xml");
function goto(thisXML) {
var rootNode = thisXML.firstChild;
for (i=0; i<rootNode.childNodes.length; i++) {
var my_ar = new Array();
my_ar = rootNode.childNodes.firstChild.nodeValue;
trace(my_ar)
}
}
}
private function array() {
//trace(my_ar)
}
}

xml fajl:

<?xml version="1.0" encoding="utf-8"?>
<pictures>
<name>auto</name>
<name>kuca</name>
<name>avion</name>
<name>kamion</name>
<name>lopta</name>
<name>olovka</name>
<name>knjiga</name>
</pictures>
 
Odgovor na temu

Vranac
Vranac Srdjan
Software developer
Novi Sad, Vojvodina

Član broj: 3493
Poruke: 353
..mtsns-ns.customer.sbb.co.yu.

Jabber: vranac@elitesecurity.org
ICQ: 64150005
Sajt: www.linkedin.com/in/vrana..


+1 Profil

icon Re: private function()24.04.2006. u 18:21 - pre 219 meseci
problem je sto ti je my_ar bila lokalna varijabla u funkciji,
kad je deklarises u klasi i inicijalizujes u konstruktoru onda neces dobijati
"There is no property with the name 'my_ar." error.

Mada moj predlog ti je da promenis ime f-je iz Array, obzirom da je to reserved keyword.

Code:

class pitanje extends MovieClip {
    var i:Number;
    var my_ar:Array; 
    function pitanje() {
        my_ar = new Array();
        loadXML();
        array();
    }
    private function loadXML() {
        var xmlData:XML;
        xmlData = new XML();
        xmlData.ignoreWhite = true;
        xmlData.onLoad = function(ok) {
            if (ok) {
                goto(xmlData);
            }
        };
        xmlData.load("pitanje.xml");
        function goto(thisXML) {
            var rootNode = thisXML.firstChild;
            for (i=0; i<rootNode.childNodes.length; i++) {
                //var my_ar = new Array();
                my_ar = rootNode.childNodes.firstChild.nodeValue;
                trace(my_ar);
            }
        }
    }
    private function array() {
        trace(my_ar)
    }
}


Idle mind is the devils playground, in my case it turned out to be an amusement park.

Sustina problema ove zemlje:
Legeonar_: Sto pre treba da shvatite da je EU propast i da se tamo mora raditi,a ne samo biti zaposlen.
http://www.elitemadzone.org/p1864861

Nobody Remains Virgin, Life Fucks Everyone
 
Odgovor na temu

sekvoja

Član broj: 91239
Poruke: 269
*.ptt.yu.



Profil

icon Re: private function()26.04.2006. u 13:37 - pre 219 meseci
Hvala na trudu, ali onda ne mogu da trejsujem elemente iz XML-a.
 
Odgovor na temu

Vranac
Vranac Srdjan
Software developer
Novi Sad, Vojvodina

Član broj: 3493
Poruke: 353
..mtsns-ns.customer.sbb.co.yu.

Jabber: vranac@elitesecurity.org
ICQ: 64150005
Sajt: www.linkedin.com/in/vrana..


+1 Profil

icon Re: private function()26.04.2006. u 14:28 - pre 219 meseci
U pravu si, tako mi i treba kad odgovaram na frku.
Nego, ako sam dobro razumeo ti hoces vrednost svakog name node-a da stavis u Array i da mozes da mu pristupas iz druge funkcije.
Ukoliko je to slucaj, onda je ovo kod za Flash 8

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;
    
    // 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);
        
        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);
            }
            
            // 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)
    }
}


output ove klase je:
Code:

loadXML
<?xml version="1.0" encoding="utf-8"?><pictures><name>auto</name><name>kuca</name><name>avion</name><name>kamion</name><name>lopta</name><name>olovka</name><name>knjiga</name></pictures>
my_ar = auto
my_ar = auto,kuca
my_ar = auto,kuca,avion
my_ar = auto,kuca,avion,kamion
my_ar = auto,kuca,avion,kamion,lopta
my_ar = auto,kuca,avion,kamion,lopta,olovka
my_ar = auto,kuca,avion,kamion,lopta,olovka,knjiga
array = auto,kuca,avion,kamion,lopta,olovka,knjiga


Idle mind is the devils playground, in my case it turned out to be an amusement park.

Sustina problema ove zemlje:
Legeonar_: Sto pre treba da shvatite da je EU propast i da se tamo mora raditi,a ne samo biti zaposlen.
http://www.elitemadzone.org/p1864861

Nobody Remains Virgin, Life Fucks Everyone
 
Odgovor na temu

[es] :: Flash :: private function()

[ Pregleda: 2160 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.