-
misunderstanding about "with"
i thought that what "with (myObj){statements}" does making myObj execute statements. however this seems to not be completely true:
i have 2 vars with the same name: myVar
one is in class mainClass, the other is declared in the with statements. when i change myVar within the with statements, and trace it, back in mainClass the change to the var myVar in mainClass is (also?) made.
so what does with do really?
-
with (obj) {} is used to set properties on the object, not execute statements.
example:
PHP Code:
with(obj) { alpha = 0; visible = false; x = 0; y = 0; }
-
With only affects properties and methods. For example, this doesn't work because var a is defined twice in the same namespace (you can't say m.var a = ""):
PHP Code:
var m:MovieClip = new MovieClip();
var a:String = 'outside';
with(m){
var a:String = 'inside';
trace(a);
}
trace(a, m.a);
This does work because you have created the property on mc before going into the with statement:
PHP Code:
var m:MovieClip = new MovieClip();
var a:String = 'outside';
m.a = new String();
with(m){
a = 'inside';
trace(a);
}
trace(a, m.a);
-
but when i do:
PHP Code:
var bb:int =5; with (myObj) { trace (bb); }
it gives: undefined.
-
The same just worked for me:
PHP Code:
var m:MovieClip = new MovieClip();
var a:String = 'outside';
with(m){
trace(a);
}
Are you using a custom class? Is it dynamic or does it already have a public param/method with the same name?
-
Post your FLA file - you must be missing something.
Make sure myObj exists on the stage, otherwise it would work.
-
PHP Code:
public class MainClass extends MovieClip { private var t1e:Number; var bla1:AccDirSpd = new AccDirSpd(); public function MainClass() { t1e = 5; trace(t1e); with (bla1) { trace(t1e); var t1e:Number; t1e = 7; trace(t1e); } trace(t1e); } }
AccDirSpd class has no t1e var.
-
What does this give you?
PHP Code:
public class MainClass extends MovieClip { private var bla1:AccDirSpd = new AccDirSpd(); private var t1e:Number; public function MainClass() { with (bla1) { t1e = 7; trace(t1e); } } }
-
7. and out of the with statement also 7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|