Ask a Question related to Macromedia Flash Actionscript, Design and Development.
-
vulvair #1
Problem attaching a clip to an xml parsed object
The goal of this is to load in data form an xml file, attach the data to a
custom object, and associate the object with a movieclip (library item).
I've done this in the following way, my only problem is getting the library
item to associate itself with object the xml data has been put into.
1:
I've created an object called phone which has various properties (price,
pixels etc) (this works)
2:
I get the data for each phone from an xml file (this works)
3:
When each object has been created, I then move to frame 2, and attach each
phone object to the library item phone0.
At frame 2, although I can access the properties of the object directly, I
cannot do so via the movie clip it is attached to, I hope the code I show you
will explain everything.
Discussion:
I was thinking of maybe accessing the movie class's prototype to give it the
new properties, but I don't think this is the right approach. Instad, on my
frame 2 code, you'll see that I've been trying to solve the problem using the
attachMovie code, hopefully it's just a sytnax error.
This is actionscript 1 for mx, and the library item ahs the linkage identifier
phone0
//****FRAME 1******
function phone(id, price, make, pixels, ccd) {
this.id = id;
this.price = price;
this.make = make;
this.pixels = pixels;
this.ccd = ccd;
}
function makeArray(success) {
var i, j, mainTag, id, price, make, pixels, ccd;
if (success) {
for (i=0; i<=moXML.childNodes.length; i++) {
if (this.childNodes[i].nodeValue == null && this.childNodes[i].nodeName ==
"phonelist") {
mainTag = this.childNodes[i];
}
}
for (i=0; i<=mainTag.childNodes.length; i++) {
if (mainTag.childNodes[i].nodeName == "phones") {
phoneTag = mainTag.childNodes[i];
id = phoneTag.attributes["id"];
for (j=0; j<phoneTag.childNodes.length; j++) {
if (phoneTag.childNodes[j].nodeName != null) {
if (phoneTag.childNodes[j].nodeName == "price") {
price = phoneTag.childNodes[j].firstChild.nodeValue;
} else if (phoneTag.childNodes[j].nodeName == "make") {
make = phoneTag.childNodes[j].firstChild.nodeValue;
} else if (phoneTag.childNodes[j].nodeName == "pixel") {
pixels = phoneTag.childNodes[j].firstChild.nodeValue;
} else if (phoneTag.childNodes[j].nodeName == "ccd") {
ccd = phoneTag.childNodes[j].firstChild.nodeValue;
}
}
}
thisphone = new phone(id, price, make, pixels, ccd);
phones.push(thisphone);
delete thisphone;
}
}
gotoAndPlay(2);
}
}
var phones = [];
moXML = new XML();
moXML.ignoreWhite = true;
moXML.onLoad = makeArray;
moXML.load("test2.xml");
stop();
//****FRAME 2******
//Note that at the end of frame tow the library item does appear on the stage.
for?(var?prop?in?phones[0])?{
????trace("these are the props "+prop+" = "+phones[0][prop]);
}
//this lists the phone object properties
trace(phones);
//this returns [object Object],[object Object],[object Object],[object Object]
for?(i=0;?i<4;?i++)?{
????Object.registerClass("phone0",?phone);
????phone.prototype?=?new?MovieClip();
????this.attachMovie("phone0",?"phone"+i,?i);
????
}
trace(phone0.ccd);
//this returns 'undefined'????
stop();
vulvair Guest
-
dimension problem while attaching movie clip
I am attaching 5 different objects to the movie but they are being displayed on top of another even I have given different dimensions to each ... -
need help positioning movie clip relative to a resizing clip...
I am trying to attach a "caption" to the bottom right edge of a movie clip that resizes. I am using the resizing clip as a image holder for a... -
play clip, remove clip, load new clip
I have an empty 'container' MC that has a MovieClip load into it when a button is pressed.....when another button is pressed, it should play the... -
Problem Attaching Sound to Button using Behavior
I am having much trouble trying to get a sound file to play with a Button "Behavior". If someone could tell me what I am doing wrong I would... -
Embedding a Cult3D object in a flash clip
Hey! I would like to embedd a cult3d object in a flash clip, but i don't know how to do it. Also, what do you think of Cult3D compared to...



Reply With Quote

