开发者

Referencing argument in with statement

I开发者_C百科s there a way to reference the argument in a with statement? It's like when you have class variables and a constructor and you do this

var blah;
public function foo(blah) {
    this.blah = blah;
}

Is there a way to do the same like

public function foo(blah) {
    with(cat){
        bar += blah;
    }
}

I want to add cat.bar by the blah given to the function.

It's easy to just rename the argument, but I'm curious if there's a way to do it. Thanks


That's what the with is for

tried this in wonder.fl and it works fine. Can you specify what you were expecting to see vs what it did?

package {
    import flash.text.TextField;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {

        public var myMC:Sprite = new Sprite();    
        public var tf:TextField = new TextField();    

        public function FlashTest() {

            addChild(tf);

            fooWith(20);

        }

        public function fooWith($x:Number):void{

            with(myMC){
                x+=$x;
            }

            tf.text =  "' "  + myMC.x + " '";
        }

    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜