Flex requires variables to be declared somewhere in a function, but
doesn't care where it just rolls all variable definitions to the top
of the function, so there is a phantom var val:String; at the top of
the function.  At the point where you call validateRequired val
exists, but hasn't had a value assigned so it is null which is what
you are seeing.

No different than if you declared a variable without assigning a value
in a language that required declaration at the top of the function.

--- In [email protected], "Mika Kiljunen" <[EMAIL PROTECTED]>
wrote:
>
> Hi!
> I ran into this "weird" situation that as a programmer I think is a
bug, but
> I'm not sure if this is true in the flex world. See following code
snippet,
> especially how the variable "val" is defined (it is used at
> "validateRequired" function call before it's even defined and Flex
Builder
> compiles it without a single error or warning, resulting on faulty
> functionality since "val" gets used as value "null".)
> 
> Is this correct behaviour that one should be beware of?
> 
> ....
> public function validateString(
value:String,options:StringValidatorOptions,
> language:ICommonLanguage ) : Array
>             {
>             var results:Array = new Array();
>             // Validate required
>             var requiredError:ValidationError = validateRequired( val,
> options, language );
>             if ( requiredError )
>                 {
>                 results.push( requiredError );
>                 return results;
>                 }
> 
>             var val:String = ( value != null ? String(value) : "" );
> .....
> 
> Thanks,
> Mika
>


Reply via email to