onLoad Event
- Lord Sivell
- Novice


- Joined: Dec 08, 2003
- Posts: 32
- Loc: Australia
- Status: Offline
Hey,
I'm having problems with this script:
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.
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;
}
}
};
_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;
}
}
};
- 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;
- }
- }
- };
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


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
May 20th, 2005, 11:12 pm
- lostinbeta
- Guru


- Joined: Jun 26, 2003
- Posts: 1402
- Loc: Philadelphia, PA
- Status: Offline
- Lord Sivell
- Novice


- Joined: Dec 08, 2003
- Posts: 32
- Loc: Australia
- Status: Offline
- contstrictor
- Novice


- Joined: May 23, 2005
- Posts: 26
- Status: Offline
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
Hope it helps
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 4 posts
- Users browsing this forum: No registered users and 41 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
