It would be great if this were in the reference with the method tag... not sure where the javascript syntax goes. I noticed in the javasscript init method there was new "override" syntax... is that needed in the tag syntax also? only required for SWF9 or all runtimes?

Thanks!
Sarah


On Jan 9, 2009, at 10:21 AM, P T Withington wrote:

[cc-ing Lou, this needs to go in the documentation somewhere...]

This is JS2 syntax for an optional argument with a default value. Means you can dispense with any switch/cascading-if arguments.length bs when defaulting your arguments. The compiler does all the work for you (and it is free in swf9!)

You can say the exact same thing in LZX:

<method name="play" arguments="start='either', pause=false, length='end', reset=true">

Note all optional arguments must follow all required arguments.

Also adopted from JS2, if you just want to accept and gather up all the rest of the arguments:

 function foo (required, optional=null, rest...)

the argument `rest` (can be any name) will be bound to a list of arguments 3 - Infinity. If you have a function that takes variable arguments, you _have_ to make this declaration for swf9 to work.

Finally, you can declare the types of your arguments. These types are ignored in the JS1 back-ends, but they are enforced in JS2 (swf9).

 function foo (required:String, optional:Boolean=false)

Caution: You will get a type error, but _only_ if there is not a coercion available. Hence, passing `null` as the first argument to foo above will cause it to be called with the string "null", not the null value. If you want a nullable type, you should leave the type undeclared (for now...).

On 2009-01-09, at 13:07EST, Sarah Allen wrote:

more syntax questions:

mediastream.lzx defines a function like this:
function play (start='either', pause=false, length='end', reset=true)

I'm not familiar with that syntax. Can someone tell me about it and also let me know the syntax for how to express the same thing in a method tag? (or point me to docs)

Thanks,
Sarah


Reply via email to