|
-
Senior Member
object Array problem/help?
OMG!.. I can NOT for the life of me figure out what I am doing wrong here:
I am populating an OBJECT ARRAY.... and passing it into the 'attachedClip' form the library.. the clip in the library has a function hardCoded into it..to work/grab the values from the objectArray once it is pushed into it..
Code:
//----- line API code -----//
function lineOn(){
for(i=0; i<connectionArray.length; i++){
_parent.createEmptyMovieClip("line", 100+i);
this.swapDepths((100+i)+_parent.getNextHighestDepth());
_parent.line.lineStyle([connectionArray[i]].lineThickness, "0x" + [[connectionArray[i]].lineColor], 100);
//_parent.line.lineStyle(this.lineThickness, "0x" + this.lineColor, 100);
_parent.line.moveTo(this._x, this._y);
trace("Clip "+[connectionArray[i].id]+" X: "+_parent[connectionArray[i].id]._x+" / Y: "+_parent[connectionArray[i].id]._y);
trace("Distance: "+connectionArray[i].distance+" / Time: "+connectionArray[i].time);
_parent.line.lineTo(_parent[connectionArray[i].id]._x, _parent[connectionArray[i].id]._y);
}
trace("----------------");
};
I have been all over the place.. creating NEW vars.. strict data typing as well.. eval, Number() function...etc..etc.. nothing has worked.. I can trace out my values in the object array fine... but using them in the function to PLACE/DRAW the API line..just will NOT work..
I think I may have been looking at it for too long..LOL Im not sure whatthe deal is..since I can target/path to it..and trace out the values.. but I can NOT eithe, convert to a number to be used in the lineTo method(), or something...
any ideas??
thanks gang..
-
Senior Member
 Originally Posted by whispers
OMG!.. I can NOT for the life of me figure out what I am doing wrong here:
I am populating an OBJECT ARRAY.... and passing it into the 'attachedClip' form the library.. the clip in the library has a function hardCoded into it..to work/grab the values from the objectArray once it is pushed into it..
Code:
//----- line API code -----//
function lineOn(){
for(i=0; i<connectionArray.length; i++){
_parent.createEmptyMovieClip("line", 100+i);
this.swapDepths((100+i)+_parent.getNextHighestDepth());
_parent.line.lineStyle([connectionArray[i]].lineThickness, "0x" + [[connectionArray[i]].lineColor], 100);
//_parent.line.lineStyle(this.lineThickness, "0x" + this.lineColor, 100);
_parent.line.moveTo(this._x, this._y);
trace("Clip "+[connectionArray[i].id]+" X: "+_parent[connectionArray[i].id]._x+" / Y: "+_parent[connectionArray[i].id]._y);
trace("Distance: "+connectionArray[i].distance+" / Time: "+connectionArray[i].time);
_parent.line.lineTo(_parent[connectionArray[i].id]._x, _parent[connectionArray[i].id]._y);
}
trace("----------------");
};
I have been all over the place.. creating NEW vars.. strict data typing as well.. eval, Number() function...etc..etc.. nothing has worked.. I can trace out my values in the object array fine... but using them in the function to PLACE/DRAW the API line..just will NOT work..
I think I may have been looking at it for too long..LOL Im not sure whatthe deal is..since I can target/path to it..and trace out the values.. but I can NOT eithe, convert to a number to be used in the lineTo method(), or something...
any ideas??
thanks gang..
I'm noticing two things:
You mention that the clip in the library has a hard coded function, but this:
_parent.createEmptyMovieClip("line", 100+i);
Is creating an empty movie clip, not attaching anything from the library.
Also, you are creating n clips, all named "line" Flash doesn't know what to do if it has mutiple instances with the same name.
Beyond that, I really can't tell without seeing more, but that's what leaps out at me.
Hope this helps.
d.
-
Senior Member
As a follow up, you should be writing something like this:
Code:
//----- line API code -----//
function lineOn(){
for(i=0; i<connectionArray.length; i++){
var _clip:MovieClip = _parent.createEmptyMovieClip(("line" + i), 100+i);
this.swapDepths((100+i)+_parent.getNextHighestDept h());
_clip.lineStyle([connectionArray[i]].lineThickness, "0x" + [[connectionArray[i]].lineColor], 100);
_clip.moveTo(this._x, this._y);
_clip.lineTo(_parent[connectionArray[i].id]._x, _parent[connectionArray[i].id]._y);
}
};
This way you create a local variable named "_clip" and use to reference it. I can't promise there isn't another issue going on, but should solve your immediate issue.
d.
-
Senior Member
hi.
thanks for the reply... I see what you mean about the 'line' clip being created...
but thats 'not' the problem.. even 'fixing it' your way doesnt solve my initial post question.
I had more or less the EXACT same code:
Code:
//----- line API code -----//
function lineOn(){
for(i=0; i<connectionArray.length; i++){
_parent.createEmptyMovieClip("line", 100+i);
this.swapDepths((100+i)+_parent.getNextHighestDepth());
_parent.line.lineStyle(_parent[connectionArray[i]].lineThickness, "0x" + [_parent[connectionArray[i]].lineColor], 100);
//_parent.line.lineStyle(this.lineThickness, "0x" + this.lineColor, 100);
_parent.line.moveTo(this._x, this._y);
_parent.line.lineTo(_parent[connectionArray[i]]._x, _parent[connectionArray[i]]._y);
}
};
working fine....
it wasnt until I changed my loop (which populates my array in EACH attached clip)
from this:
Code:
locationClip.connectionArray.push(xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[6].childNodes[z].firstChild.nodeValue);
to this:
Code:
locationClip.connectionArray.push({id:xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[6].childNodes[z].firstChild.nodeValue, distance:xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[6].childNodes[z].attributes.distance, time:xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[6].childNodes[z].attributes.time});
and trying to lineTo() as follows now... (again above method WORKS.. the bottom does NOT)
Code:
//----- line API code -----//
function lineOn(){
for(i=0; i<connectionArray.length; i++){
_parent.createEmptyMovieClip("line", 100+i);
this.swapDepths((100+i)+_parent.getNextHighestDept h());
_parent.line.lineStyle([connectionArray[i]].lineThickness, "0x" + [[connectionArray[i]].lineColor], 100);
//_parent.line.lineStyle(this.lineThickness, "0x" + this.lineColor, 100);
_parent.line.moveTo(this._x, this._y);
trace("Clip "+[connectionArray[i].id]+" X: "+_parent[connectionArray[i].id]._x+" / Y: "+_parent[connectionArray[i].id]._y);
trace("Distance: "+connectionArray[i].distance+" / Time: "+connectionArray[i].time);
_parent.line.lineTo(_parent[connectionArray[i].id]._x, _parent[connectionArray[i].id]._y);
}
trace("----------------");
};
I am basically going from a regular array to pushing an object into the array.. which offers me more data that I can trace just fine..but can seem to use in the lineTo() function... like posted above..
grrrrr.. I have tried everything.. eval(), Number(), [] ...declaring vars for all and portions of the path/var...
anyone have any ideas??
Last edited by whispers; 07-27-2007 at 07:43 PM.
-
Learning Flash
unclutter for clarity
I have to say, it's really confusing trying to follow your code and your situation... it's too complex (and I think this is why you can't see what's wrong)
If you change the connectionArray content to an object, don't you also need to change the way you access that content in all places you access it? It seems you changed it from a single value, to an object with properties id, distance and time. And the value that used to be at connectionArray[i] is now at connectionArray[i].id?
You made this change in access for the last line in the loop. But not for the earlier line:
Code:
_parent.line.lineStyle([connectionArray[i]].lineThickness, "0x" + [[connectionArray[i]].lineColor], 100);
I can't tell if this is "the" problem - but my suggestion is to simplify and unclutter the code, by factoring out the references, like this:
Code:
id = _parent[connectionArray[i].id]
I think if you unclutter it like this, the clarity will make the problem immediately apparent to you (whatever it is).
code tested in Flash Basic 8 (AS2), Windows XP
-
Senior Member
this line:
Code:
_parent.line.lineStyle([connectionArray[i]].lineThickness, "0x" + [[connectionArray[i]].lineColor], 100);
is accessing a VALUE (variable) that was passed into the clip when it was attached to the stage. I dump several other variables INTO THE ATTACHED CLIPS' timeline/scope.. so they can be access by the clip itself and other code through out the project.
SO Im not sure how else to go about accessing that data then.. (cause it works like that now)
and I have tried to simplify, and name VARS, [], eval(), Number()...etc. (as stated above)
Code:
var xLoc = _parent[connectionArray[i].id];
var yLoc = _parent[connectionArray[i].id];
var xNum:Number = xLoc._x;
var yNum:Number = yLoc._y;
and tons of other ways... still no luck!!?? 
?????
also.. Im un-sure of why what your calling 'clutter' would stop the lineTo() function?? because I can TRACE everything.. all mytrace lines you see WORK.. and output the correct values. 
Im stumped..
Last edited by whispers; 07-27-2007 at 08:16 PM.
-
Senior Member
Yow-
your first line sparked me to trace out ALL my vars...
and I cant seem to access values/variables that I attached/dumped into each Clip when I attached it to the stage...
Seems I have a scope issue somewhere?..but I have no clue where...
how can I NOT be able to access values in other clips?..LOL
so this IS the problematic line now: (confirmed)
Code:
_parent.line.lineStyle([connectionArray[i]].lineThickness, "0x" + [[connectionArray[i]].lineColor], 100);
but Im not sure on how to correct it I guess??
her is the code I used to attach and pas in my data to each clip:
Code:
for(i=0; i<totalLocations; i++){
var locationClip = attachMovie("locationObject", xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[0].firstChild.nodeValue, 1000 + i);
var locX = Number(Math.round(xmlSource.firstChild.childNodes[2].childNodes[i].attributes.x));
var locY = Number(Math.round(xmlSource.firstChild.childNodes[2].childNodes[i].attributes.y));
var locID = xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[0].firstChild.nodeValue;
var locName = xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[1].firstChild.nodeValue;
var locImage = xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[2].firstChild.nodeValue;
var locTitle = xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[3].firstChild.nodeValue;
var lineThickness = xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[4].firstChild.nodeValue;
var lineColor = xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[5].firstChild.nodeValue;
var totalConnections = xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[6].childNodes.length;
var connectionArray = new Array();
trace("location connects: "+totalConnections);
//pass data to each locationClip
locationClip.locX = locX;
locationClip.locY = locY;
locationClip.locationTitle = "images/" + locTitle;
locationClip.locationImage = "images/" + locImage;
locationClip.locationName = locName;
locationClip.locationID = locID;
locationClip.lineThickness = lineThickness;
locationClip.lineColor = lineColor;
locationClip.connectionArray = connectionArray;
for(z=0; z<totalConnections; z++){
trace("Location"+i+": "+xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[6].childNodes[z].firstChild.nodeValue);
//locationClip.connectionArray[z] = xmlSource.firstChild.childNodes[1].childNodes[i].childNodes[6].childNodes[z].firstChild.nodeValue;
//locationClip.connectionArray.push(xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[6].childNodes[z].firstChild.nodeValue);
locationClip.connectionArray.push({id:xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[6].childNodes[z].firstChild.nodeValue, distance:xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[6].childNodes[z].attributes.distance, time:xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[6].childNodes[z].attributes.time});
//trace("Array Details: "+locationClip.connectionArray[z]);
}
//place locationClip on stage
locationClip._x = locX;
locationClip._y = locY;
}
these are NOT variables/values put into the array...
-
Senior Member
DOH!..
you were right..the WHOLE time (and I looked at it plenty of times).. I didnt see the missing .id in the line..
Thanks Yow.. you dead on. I didnt update the other accessing paths/scopes. Thanks
-
Learning Flash
Progress!
I meant that this line:
Code:
_parent.line.lineStyle([connectionArray[i]].lineThickness, "0x" + [[connectionArray[i]].lineColor], 100);
should be this:
Code:
_parent.line.lineStyle([connectionArray[i].id].lineThickness, "0x" + [[connectionArray[i].id].lineColor], 100);
Which uncluttered would be:
Code:
ID = [connectionArray[i].id]
_parent.line.lineStyle(ID.lineThickness, "0x" + ID.lineColor], 100);
WAIT a second... that looks like an array accessor without an array! Can you do that? (I don't know all of Flash syntax)
BTW: ... in your init code, you could factor out this:
Code:
node = xmlSource.firstChild.childNodes[2].childNodes[i]
Could you post the current versions (simplified) of all the relevant parts of the code?
code tested in Flash Basic 8 (AS2), Windows XP
-
Learning Flash
you're welcome!
Last edited by yow; 07-27-2007 at 08:58 PM.
code tested in Flash Basic 8 (AS2), Windows XP
-
Senior Member
hi..you are right.
this:
[connectionArray[i]]
should have been this:
[connectionArray[i].id] and forwhatever reason I kept seeing that it was (in my mind) lol
also [] can be used the same way as eval() is used...
Thanks again.
-
Learning Flash
thanks, I didn't know that about []
code tested in Flash Basic 8 (AS2), Windows XP
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|