Hi Jimmi,

your parameter is being passed by value not object since it's a literal
value.
In your previous situation the function applied itself to a global variable
so this problem didn't occur.

Add a return statement to your function at the end:
function interpunk (par1):Void {
.....
return par1;
}

And call it like: outputString = interpunk (outputString);

Note however that reassigning parameter values is not considered good
practice, and you should avoid it.


HTH
JC

On Fri, Apr 3, 2009 at 10:19 AM, jimmi <[email protected]> wrote:

> Good morning,
>
> I have made a function that adds interpunction marks to a value, for
> example the value 10000 gets changed to 10.000, 100000 to 100.000 and
> so forth.
>
> The function work fine, but I'm trying to make it reusable so that i
> can use it in a large scale project. That's where the problem comes
> up.
>
> This is what the working code looks like:
>
>
> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> var outputNumber:Number = 10000 // input value
> var outputString:String = new String();
>
> function init ()
> {
>        outputString = String(Number(outputNumber));
>        interpunk (outputString);
>
>        trace(outputNumber); // output is 10000
>        trace(outputString); // output is 10.000
> }
>
> function interpunk (par1):Void
> {
>        trace(par1)
>        switch (par1.length)
>        {
>                case 4 :
>                        outputString = String(par1.charAt (0) + "." +
> par1.slice (1))
>                        break;
>
>                case 5 :
>                        outputString = String(par1.charAt (0) + par1.charAt
> (1) + "." +
> par1.slice (2))
>                        break;
>
>                case 6 :
>                        outputString = String(par1.charAt (0) + par1.charAt
> (1) +
> par1.charAt (2) + "." + par1.slice (3))
>                        break;
>
>                default :
>                        outputString = String(par1)
>                        break;
>        }
> }
>
> init ();
>
>
> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> So i tried to make it reusable, so i tried this(changed outputString to
> par1).
> But now the value comes out unchanged so 10000 stays 10000, while i
> expected it to become 10.000.
>
>
> I hope someone can help i the right direction.
>
> This is what the non working code looks like :
>
>
> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> function interpunk (par1):Void
> {
>        trace(par1)
>        switch (par1.length)
>        {
>                case 4 :
>                        par1 = String(par1.charAt (0) + "." + par1.slice
> (1))
>                        break;
>
>                case 5 :
>                        par1 = String(par1.charAt (0) + par1.charAt (1) +
> "." + par1.slice (2))
>                        break;
>
>                case 6 :
>                        par1 = String(par1.charAt (0) + par1.charAt (1) +
> par1.charAt (2) +
> "." + par1.slice (3))
>                        break;
>
>                default :
>                        par1 = String(par1)
>                        break;
>        }
> }
>
>
> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to