onLoad Event

  • Lord Sivell
  • Novice
  • Novice
  • Lord Sivell
  • Posts: 32
  • Loc: Australia

Post 3+ Months Ago

Hey,

I'm having problems with this script:
Code: [ Select ]
stop();

_root.threads = new Array();

_root.createEmptyMovieClip("lines", 0);
_root.lines.count = 0;
_root.createEmptyMovieClip("links", 1);
_root.links.count = 0;

_root.id = "home";

MovieClip.prototype.addLinks = function(isFirst) {
    this.linksXML = new XML();
    this.linksXML.ignoreWhite = true;
    this.linksXML.load("http://www.particlesystem.com/particlesystem/assets/get_links.php?id="+this.id);
    this.linksXML.onLoad = function() {
        for (var i=0; i<linksXML.childNodes.length; i++) {
            var threadsLength = _root.threads.length;
            _root.threads[threadsLength] = new Object();
            _root.threads[threadsLength].lineNumber = _root.lines.count;
            _root.threads[threadsLength].id = String(linksXML.childNodes[i].firstChild);
            _root.threads[threadsLength].percent = 0;
            _root.threads[threadsLength].targetX = 400*Math.random()+50;
            _root.threads[threadsLength].targetY = 150*Math.random()+25;
            if (!isFirst) {
                _root.threads[threadsLength].startX = x;
                _root.threads[threadsLength].startY = y;
                _root.threads[threadsLength].alpha = alpha*0.75;
            } else {
                _root.threads[threadsLength].startX = 500*Math.random();
                _root.threads[threadsLength].startY = 0;
                _root.threads[threadsLength].alpha = 100;
            }
            _root.lines.createEmptyMovieClip("L"+_root.lines.count, _root.lines.count);
            _root.lines.count++;
        }
    };
};

_root.addLinks(true);

_root.onEnterFrame = function() {
    for (var i=0; i<_root.threads.length; i++) {
        _root.threads[i].percent += (1-_root.threads[i].percent)/10;
        _root.lines["L"+_root.threads[i].lineNumber].clear();
        _root.lines["L"+_root.threads[i].lineNumber].lineStyle(1, "0x666666", _root.threads[i].alpha);
        _root.lines["L"+_root.threads[i].lineNumber].moveTo(_root.threads[i].startX, _root.threads[i].startY);
        _root.lines["L"+_root.threads[i].lineNumber].lineTo(_root.threads[i].startX-(_root.threads[i].startX-_root.threads[i].targetX)*_root.threads[i].percent, _root.threads[i].startY-(_root.threads[i].startY-_root.threads[i].targetY)*_root.threads[i].percent);
        if (_root.threads[i].percent == 1) {
            _root.links.attachMovie("link", "L"+_root.links.count, _root.links.count);
            _root.links["L"+_root.links.count]._x = _root.links["L"+_root.links.count].x = _root.threads[i].targetX;
            _root.links["L"+_root.links.count]._y = _root.links["L"+_root.links.count].y = _root.threads[i].targetY;
            _root.links["L"+_root.links.count]._alpha = _root.links["L"+_root.links.count].alpha = _root.threads[i].alpha;
            _root.links["L"+_root.links.count].id = _root.threads[i].id;
            _root.links["L"+_root.links.count].addLinks(false);
            _root.links.count++;
            _root.threads.splice(i, 1);
        } else if (Math.round(_root.threads[i].percent*10)/10 == 1) {
            _root.threads[i].percent = 1;
        }
    }
};
  1. stop();
  2. _root.threads = new Array();
  3. _root.createEmptyMovieClip("lines", 0);
  4. _root.lines.count = 0;
  5. _root.createEmptyMovieClip("links", 1);
  6. _root.links.count = 0;
  7. _root.id = "home";
  8. MovieClip.prototype.addLinks = function(isFirst) {
  9.     this.linksXML = new XML();
  10.     this.linksXML.ignoreWhite = true;
  11.     this.linksXML.load("http://www.particlesystem.com/particlesystem/assets/get_links.php?id="+this.id);
  12.     this.linksXML.onLoad = function() {
  13.         for (var i=0; i<linksXML.childNodes.length; i++) {
  14.             var threadsLength = _root.threads.length;
  15.             _root.threads[threadsLength] = new Object();
  16.             _root.threads[threadsLength].lineNumber = _root.lines.count;
  17.             _root.threads[threadsLength].id = String(linksXML.childNodes[i].firstChild);
  18.             _root.threads[threadsLength].percent = 0;
  19.             _root.threads[threadsLength].targetX = 400*Math.random()+50;
  20.             _root.threads[threadsLength].targetY = 150*Math.random()+25;
  21.             if (!isFirst) {
  22.                 _root.threads[threadsLength].startX = x;
  23.                 _root.threads[threadsLength].startY = y;
  24.                 _root.threads[threadsLength].alpha = alpha*0.75;
  25.             } else {
  26.                 _root.threads[threadsLength].startX = 500*Math.random();
  27.                 _root.threads[threadsLength].startY = 0;
  28.                 _root.threads[threadsLength].alpha = 100;
  29.             }
  30.             _root.lines.createEmptyMovieClip("L"+_root.lines.count, _root.lines.count);
  31.             _root.lines.count++;
  32.         }
  33.     };
  34. };
  35. _root.addLinks(true);
  36. _root.onEnterFrame = function() {
  37.     for (var i=0; i<_root.threads.length; i++) {
  38.         _root.threads[i].percent += (1-_root.threads[i].percent)/10;
  39.         _root.lines["L"+_root.threads[i].lineNumber].clear();
  40.         _root.lines["L"+_root.threads[i].lineNumber].lineStyle(1, "0x666666", _root.threads[i].alpha);
  41.         _root.lines["L"+_root.threads[i].lineNumber].moveTo(_root.threads[i].startX, _root.threads[i].startY);
  42.         _root.lines["L"+_root.threads[i].lineNumber].lineTo(_root.threads[i].startX-(_root.threads[i].startX-_root.threads[i].targetX)*_root.threads[i].percent, _root.threads[i].startY-(_root.threads[i].startY-_root.threads[i].targetY)*_root.threads[i].percent);
  43.         if (_root.threads[i].percent == 1) {
  44.             _root.links.attachMovie("link", "L"+_root.links.count, _root.links.count);
  45.             _root.links["L"+_root.links.count]._x = _root.links["L"+_root.links.count].x = _root.threads[i].targetX;
  46.             _root.links["L"+_root.links.count]._y = _root.links["L"+_root.links.count].y = _root.threads[i].targetY;
  47.             _root.links["L"+_root.links.count]._alpha = _root.links["L"+_root.links.count].alpha = _root.threads[i].alpha;
  48.             _root.links["L"+_root.links.count].id = _root.threads[i].id;
  49.             _root.links["L"+_root.links.count].addLinks(false);
  50.             _root.links.count++;
  51.             _root.threads.splice(i, 1);
  52.         } else if (Math.round(_root.threads[i].percent*10)/10 == 1) {
  53.             _root.threads[i].percent = 1;
  54.         }
  55.     }
  56. };


The problem is that if I try to say this.linksXML or this.x or this.anything in the linksXML.onLoad function it makes 'this' the linksXML object, not the movieclip its in. Is the another way to wirte this? I thought that the function could be written seperately and then envoked by the onLoad event, but that didn't seem to work... maybe I did it wrong.

Anyway any help would be great.
Thx.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Try using this._parent It should be the _parent of the XML object... which sounds like what you are trying to target.
  • Lord Sivell
  • Novice
  • Novice
  • Lord Sivell
  • Posts: 32
  • Loc: Australia

Post 3+ Months Ago

Yeah, I am trying to target the parent of the XML object. If I try to use this._parent it doesn't seem to work. Does the _parent property only work with movieclip objects?
  • contstrictor
  • Novice
  • Novice
  • contstrictor
  • Posts: 26

Post 3+ Months Ago

You should probably try the absolute path. like "_root.MC.MC" From my understanding you have written a class and if you reference "this" from within a class you a refering to the class you are calling "this" from. I usually use absolute paths when i have such problems so that the class works no matter where a method is called from because it's calling variables from an absolute location.

Hope it helps

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 20 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.