Drawd
06-13-2006, 03:55 PM
question regarding prototyping. Currently parsing an xml file to load up images for a ticker of sorts. Having issues with the prototype not applying to dynamically created MC. I've read that dynamically created MC delete all inheritance which may be the reason why this isn't working. The following is the code I am using.
The XML part works fine, but just though I would include it so you can see what variables are being used.
//---XML Loader
function loadXML(loaded){
if(loaded){
xmlNode = this.firstChild;
image = [];
description = [];
total = xmlNode.childNodes.length
for(i=0; i<total; i++){
description[i] =
xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
image[i] =
xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
trace("Image: " + image[i] + " | Description: " + description[i]);
}
createClip();
} else {
content="File not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("clients.xml");
//---PROTOTYPE CODE---
function createClip()
{
for(i=1; i<=total; i++){
trace(i);
_root.createEmptyMovieClip("client"+i, i);
_root["client"+i]._alpha = 100;
_root["client"+i].loadMovie(image[i-1]);
_root["client"+i]._x = 150 * i;
_root["client"+i]._y = 94.5;
_root["client"+i].moveHrz(Math.random() * 10);
trace(_root["client"+i]._name);
}
}
MovieClip.prototype.moveHrz = function (myVel){
this.onEnterFrame = function(){
this._x -= myVel;
if(this._x < -this._width/2)
this._x = 547 + (this._width/2)
};
};
I should mention that if I call the prototype on the main timeline it works. as in the entire movie scrolls. But obviously I would like this to happen to the MC individually.
The XML part works fine, but just though I would include it so you can see what variables are being used.
//---XML Loader
function loadXML(loaded){
if(loaded){
xmlNode = this.firstChild;
image = [];
description = [];
total = xmlNode.childNodes.length
for(i=0; i<total; i++){
description[i] =
xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
image[i] =
xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
trace("Image: " + image[i] + " | Description: " + description[i]);
}
createClip();
} else {
content="File not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("clients.xml");
//---PROTOTYPE CODE---
function createClip()
{
for(i=1; i<=total; i++){
trace(i);
_root.createEmptyMovieClip("client"+i, i);
_root["client"+i]._alpha = 100;
_root["client"+i].loadMovie(image[i-1]);
_root["client"+i]._x = 150 * i;
_root["client"+i]._y = 94.5;
_root["client"+i].moveHrz(Math.random() * 10);
trace(_root["client"+i]._name);
}
}
MovieClip.prototype.moveHrz = function (myVel){
this.onEnterFrame = function(){
this._x -= myVel;
if(this._x < -this._width/2)
this._x = 547 + (this._width/2)
};
};
I should mention that if I call the prototype on the main timeline it works. as in the entire movie scrolls. But obviously I would like this to happen to the MC individually.