PDA

View Full Version : problem with parameter.removeItem()


petefs
12-13-2004, 06:18 AM
I'm working on a wizard for a component and I'm having problems clearing a parameter of type array. I've just started learning JSFL tonight, so it could certainly be a misunderstanding of the DOM : )

Here's the code that doesn't work:

fl.outputPanel.clear();
var timeline = fl.getDocumentDOM().getTimeline();
var currentLayer = timeline.currentLayer;
var currentFrame = timeline.currentFrame;

// get the instance of the RoboRect class
function getClassItem(className)
{
var elements_array = timeline.layers[currentLayer].frames[currentFrame].elements;
var i = elements_array.length;
while(i--)
{
var item = elements_array[i];
if(item.libraryItem.linkageClassName == className) {
var classItem = item;
}
}
return classItem;
}

var RoboRect = getClassItem("Jstest");
var drawArray = RoboRect.parameters[0];
drawArray.insertItem(0, "fills", [5,10,20], "Array");
drawArray.removeItem(0);


It adds just fine -- but the remove doesn't work. If I start blank and run the script, it inserts the array. It should be removed immediately thereafter. Any hints? ^_^

splict
12-13-2004, 06:53 PM
Strangely enough, I can't get any code to execute after that line. Are you having that issue, too, or am I just screwing something else up? (I don't really have a proper component to test on here)

petefs
12-13-2004, 11:40 PM
Nope, you're right. can't even fl.trace anything : ) if you comment the removeItem() line then it works fine.

Great, I love clearing large component parameter arrays manually every time I run the script :b

splict
12-14-2004, 02:17 AM
This is weird. I really wish it would just throw an error. :mad: I have managed to make it silently quit with just a trace, too. The example I'm working on chokes when trying to trace the value of the parameter's listIndex.

petefs
12-14-2004, 03:03 AM
well, after working on some other jsfl code I've noticed that when I tried to user the insertItem() method on a non-array/object parameter it silently failed as well. After pointing it to the proper parameter the script ran again.

This may mean that I'm simply doing something wrong with regaurds to removeItem (although I can't see how that would be). Either way silently failing is wack : (

petefs
12-17-2004, 11:54 PM
For anyone interested, I found a workaround. It seems to be impossible to return the array/object parameter to an empty state -- I can, however, use removeItem at the index 1. So use this:

while(drawArray.value.length>1) drawArray.removeItem(1);

and then when you want to insert new values, just access the first item as such:
drawArray.value[0].value = "your param value";
then use drawArray.insertItem() as you would normally.

It works, that's all I can ask for right now ^_^

hangalot
12-21-2004, 05:05 PM
thanks for the sollution