What's your input structure? Are you sure they are null elements
you're trying to strip?
There are a couple of problems in your JS code:
- The result type should be an Object, and you assign the result value
by setting the named property of that object before returning the
object (not the array as in your code)
- You don't need to input the length of the structure to the JS patch,
JS can get the length of the structure itself using .length
- You use .push() on an Array object to add an element, not .add()
- Your JS patch will run first time round in _testMode, which means
that inputStructure would be null. Unless you catch this, you'll get a
compilation error.
Here's my reworked version but I'm not sure it does what you need
since testing against null won't get rid of null strings, for example.
If you're just dealing with strings, it might be better to say if
(inputStructure[i] != "") instead, or something more complex if you
can't guarantee all elements will be strings.
function (__structure outputStructure) main (__structure inputStructure)
{
myArray = new Array();
if (!_testMode) {
for (i = 0; i < inputStructure.length; i++) {
if (inputStructure[i] != null) {
myArray.push(inputStructure[i]);
}
}
}
result = new Object();
result.outputStructure = myArray;
return result;
}
Hope this helps and happy 2008 everyone!
A.
On 2 Jan 2008, at 14:57, Marcel Borsten wrote:
Hi,
Can anybody shine some light on this. I'm using an array of objects
from an XML-file, but some of the objects are empty. I need to strip
the empty objects from the array so I can use a 'clean' structure in
my composition. I've tried to use javascript, but I can't get it to
work this way (I'm no javasctipy-hero). Does anybody have any other
ideas for me:
function (__structure outputStructure) main (__structure
inputStructure, __index count)
{
result = new Array();
for (var i = 0; i < count; i++) {
if (inputStructure[i] != null) {
Array.add (result, inputStructure[i]);
}
}
return result;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartzcomposer-dev/archive%40mail-archive.com
This email sent to [EMAIL PROTECTED]