Re: [Flashcoders] Local variables and function arguments

2006-12-19 Thread Andreas R
That is quite strange, since MTASC won't give you an error for your 
first example, and Flash 8 gives no compile error when i try to use it.


Since you've been using this structure for so long:
function myFunc(tVar:String) {
   if (tVar == undefined) { tVar = limpet }
   }

What exactly is the problem it's giving you? I've been using it for 3-4 
months (that is without redeclaration) with no problems.


- A

Danny Kodicek wrote:

For, well, pretty much ever, I've worked on the assumption that in this
structure:

function myFunc(tVar:String) {
}

the variable tVar was automatically defined in local scope: that is, I can
write

function myFunc(tVar:String) {
if (tVar == undefined) { tVar = limpet }
}

But you know what? That's not true! I've just discovered (and bear in mind,
I've been using that code structure for years) that I have to declare the
variable:

function myFunc(tVar:String) {
if (tVar == undefined) {var tVar:String = limpet }
}

That seems really weird to me. Am I wrong? Is there some other explanation?

Danny

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
  


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] Local variables and function arguments

2006-12-19 Thread Jim Robson
Danny,

I just ran the following in Flash 8 (AS2) and it worked as expected: 

function testArgument(foo:String){ 
if(foo == undefined) foo = Foo was not defined;
this.txtField.text += [+foo+];
} 
testArgument();


The string, [Foo was not defined] was printed in the text field. 

-Jim

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Danny
Kodicek
Sent: Tuesday, December 19, 2006 7:53 AM
To: 'Flashcoders mailing list'
Subject: [Flashcoders] Local variables and function arguments

For, well, pretty much ever, I've worked on the assumption that in this
structure:

function myFunc(tVar:String) {
}

the variable tVar was automatically defined in local scope: that is, I can
write

function myFunc(tVar:String) {
if (tVar == undefined) { tVar = limpet } }

But you know what? That's not true! I've just discovered (and bear in mind,
I've been using that code structure for years) that I have to declare the
variable:

function myFunc(tVar:String) {
if (tVar == undefined) {var tVar:String = limpet } }

That seems really weird to me. Am I wrong? Is there some other explanation?

Danny

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training http://www.figleaf.com
http://training.figleaf.com

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Local variables and function arguments

2006-12-19 Thread Ian Thomas

That sounds totally counter to my experience, Danny. Something else must be
going on. What's the error you're getting if you omit the 'var'?

Ian

On 12/19/06, Danny Kodicek [EMAIL PROTECTED] wrote:


For, well, pretty much ever, I've worked on the assumption that in this
structure:

function myFunc(tVar:String) {
}

the variable tVar was automatically defined in local scope: that is, I can
write

function myFunc(tVar:String) {
if (tVar == undefined) { tVar = limpet }
}

But you know what? That's not true! I've just discovered (and bear in
mind,
I've been using that code structure for years) that I have to declare the
variable:

function myFunc(tVar:String) {
if (tVar == undefined) {var tVar:String = limpet }
}

That seems really weird to me. Am I wrong? Is there some other
explanation?

Danny


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] Local variables and function arguments

2006-12-19 Thread Danny Kodicek
  That sounds totally counter to my experience, Danny. 

Mine too. Plus - a simple test showed I was wrong:

function test(tVar:String) {
if (tVar == undefined) {
tVar = hello
}
}
test()
trace(tVar)

we get an undefined in the output window as expected. 

I think it's another problem which was mentioned here before: the particular
variable I was using was a movieClip, and I was setting it to _root: (the
following is stripped down slightly, missing out the bit that actually does
anything...)

function findAllFields(tRoot:MovieClip) {
if (tRoot == undefined) {   
var tRoot = _root;
} 
for (var i in tRoot) {
var tMc = tRoot[i];
if ((tMc instanceof MovieClip)  (tRoot != tMc)) {
findAllFields(tMc);
}
}
}

The line which was causing the problem was 'var tRoot = _root', which was
changed from 'tRoot = _root'. Of course, now I can't replicate the problem,
so god knows what was happening... 

 Something else must be going on. What's the error you're 
 getting if you omit the 'var'?

I was getting a '256 levels of recursion' error: tMc would be a particular
clip, but by the time I got into the recursion, it had become _root again.
My guess is it was related to the problem we saw before that _root seems to
be an instance of some other object than MovieClip (something that extends
MovieClip, presumably), so at some stage it was getting confused. Oh well,
false alarm I guess. Which is good - the idea of unpicking years of code was
a bit daunting...

Danny

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] Local variables and function arguments

2006-12-19 Thread Danny Kodicek
  That sounds totally counter to my experience, Danny. 
 Something else must be going on. What's the error you're 
 getting if you omit the 'var'?

Problem solved, and it was completely different. I was working from an older
movie and its publish settings were set to AS1! So all the typed variables
were causing it to collapse in a heap.

Danny

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] Local variables and function arguments

2006-12-19 Thread Norman Cousineau
Were you targeting Flash Player 6?  I had a similar problem which kept me up 
last night, that was fixed when I targeted FP7+.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Danny
Kodicek
Sent: Tuesday, December 19, 2006 9:08 AM
To: 'Flashcoders mailing list'
Subject: RE: [Flashcoders] Local variables and function arguments


  That sounds totally counter to my experience, Danny. 

Mine too. Plus - a simple test showed I was wrong:

function test(tVar:String) {
if (tVar == undefined) {
tVar = hello
}
}
test()
trace(tVar)

we get an undefined in the output window as expected. 

I think it's another problem which was mentioned here before: the particular
variable I was using was a movieClip, and I was setting it to _root: (the
following is stripped down slightly, missing out the bit that actually does
anything...)

function findAllFields(tRoot:MovieClip) {
if (tRoot == undefined) {   
var tRoot = _root;
} 
for (var i in tRoot) {
var tMc = tRoot[i];
if ((tMc instanceof MovieClip)  (tRoot != tMc)) {
findAllFields(tMc);
}
}
}

The line which was causing the problem was 'var tRoot = _root', which was
changed from 'tRoot = _root'. Of course, now I can't replicate the problem,
so god knows what was happening... 

 Something else must be going on. What's the error you're 
 getting if you omit the 'var'?

I was getting a '256 levels of recursion' error: tMc would be a particular
clip, but by the time I got into the recursion, it had become _root again.
My guess is it was related to the problem we saw before that _root seems to
be an instance of some other object than MovieClip (something that extends
MovieClip, presumably), so at some stage it was getting confused. Oh well,
false alarm I guess. Which is good - the idea of unpicking years of code was
a bit daunting...

Danny

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com