Toon posts:

[AS] _x en _y niet meer instelbaar

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik zit al een tijdje met een vaag probleem in Actionscript.
Het is de bedoeling om letters neer te zetten volgens in een XML file opgegeven x en y coords.
Op zich gaat het goed, alleen worden de movieclips gepositioneert in de linker bovenhoek (0,0).
Oftewel, ze reageren niet op _x en _y.

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Stage.align = "TL";
Stage.scaleMode = "noScale";
var container:MovieClip = _root.container;
var charArr:Array = new Array();
xmldoc = new XML();
xmldoc.ignoreWhite = true;
xmldoc.load("http://localhost/get_alphabet.php");
xmldoc.onLoad = function(success) {
    if (success) {
        rootnode = xmldoc.firstChild.childNodes;
        for (m=0; m<rootnode.length; m++) {
            temp = rootnode[m];
            this["charObject"+id] = new Object();
            this["charObject"+id].id = temp.attributes.id;
            this["charObject"+id].char = temp.childNodes[0].firstChild;
            this["charObject"+id].xpos = temp.childNodes[1].firstChild;
            this["charObject"+id].ypos = temp.childNodes[2].firstChild;
            charArr.push(this["charObject"+id]);
        }
        showAlphabet();
    }
};
function showAlphabet() {
    trace("charArr.length = "+charArr.length);
    for (var i = 0; i<charArr.length; i++) {
        var tid = charArr[i].id;
        container.attachMovie("mc_char_"+charArr[i].char, "char"+tid, container.getNextHighestDepth());
        container["char"+tid].id = charArr[i].id;
        container["char"+tid].char = charArr[i].char;
        container["char"+tid]._x = charArr[i].xpos; // GEEN REACTIE
        container["char"+tid]._y = charArr[i].ypos; // GEEN REACTIE
        trace("char:"+charArr[i].char+" | "+charArr[i].xpos+" | "+charArr[i].ypos); // xpos EN ypos HEBBEN WEL WAARDES
        container["char"+tid].onPress = function() {
            this.swapDepths(container.getNextHighestDepth());
            this.startDrag();
        };
        container["char"+tid].onRelease = function() {
            this.stopDrag();
            trace(this+" | "+this._x+" | "+this._y+" | "+this.char); // HIER OOK
        };
        container["char"+tid].onReleaseOutside = function() {
            this.stopDrag();
        };
    }
}


En als ik dit doe:
code:
1
2
        container["char"+tid]._x = random(Stage.width); // WEL REACTIE
        container["char"+tid]._y = random(Stage.height);  // WEL REACTIE

... werkt het wel, maar dus niet volgens de door mij gewenste xpos en ypos.

Ik heb zitten kloten met depths, daar ligt het m.i. niet aan.
Ook een setInterval (beetje vertraging), showAlphabet op 2e frame, en een onLoad werkten niet..

Iemand een tip waar ik moet kijken?

  • BtM909
  • Registratie: Juni 2000
  • Niet online

BtM909

Watch out Guys...

trace(container["char"+tid]) geeft wel een object terug?

Inkoppertje: random(Stage.width) geeft ook een waarde ongelijk aan 0 terug?

Ace of Base vs Charli XCX - All That She Boom Claps (RMT) | Clean Bandit vs Galantis - I'd Rather Be You (RMT)
You've moved up on my notch-list. You have 1 notch
I have a black belt in Kung Flu.


Verwijderd

Topicstarter
BtM909 schreef op maandag 21 november 2005 @ 11:07:
trace(container["char"+tid]) geeft wel een object terug?

Inkoppertje: random(Stage.width) geeft ook een waarde ongelijk aan 0 terug?
trace(container["char"+tid]) geeft
_level0.container.char1
t/m
_level0.container.char35
(klopt met XML file)

trace(random(Stage.width)); geeft van alles en nog wat van 0 t/m 800, dus dat klopt
zo raar dat de ene waarde wel wordt doorgegeven aan _x (random) en de andere niet (xpos)

Verwijderd

Topicstarter
Ik heb de code een beetje aangepast omdat ik dacht dat het aan de functie (en daarmee gepaard gaande variabele problemen) zou liggen.
Niet dus...

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Stage.align = "TL";
Stage.scaleMode = "noScale";
var container:MovieClip = _root.container;
var charArr:Array = new Array();
var temp, tid;
xmldoc = new XML();
xmldoc.ignoreWhite = true;
xmldoc.load("http://localhost/get_alphabet.php");
xmldoc.onLoad = function(success) {
    if (success) {
        trace("loaded!");
        rootnode = xmldoc.firstChild.childNodes;
        for (m=0; m<rootnode.length; m++) {
            temp = rootnode[m];
            container.attachMovie("mc_char_"+temp.childNodes[0].firstChild, "char"+m, container.getNextHighestDepth());
            trace(temp.childNodes[1].firstChild); // GEEFT EEN WAARDE > 0, GEHEEL VOLGENS VERWACHTING, EN VOLGENS XML
            _root.container["char"+m]._x = temp.childNodes[1].firstChild; // _x WORDT NIET GEZET
            _root.container["char"+m]._y = temp.childNodes[2].firstChild;
            container["char"+m].onPress = function() {
                this.swapDepths(container.getNextHighestDepth());
                this.startDrag();
            };
            container["char"+m].onRelease = function() {
                this.stopDrag();
                trace(this+" | "+this._x+" | "+this._y);
            };
            container["char"+m].onReleaseOutside = function() {
                this.stopDrag();
            };
        }
    }
};


Hoe kan dit nu, ik weet niet meer waar ik het zoeken moet...
iemand?