[Laszlo-dev] method in state confused about scope ?

P T Withington ptw at pobox.com
Wed Apr 2 17:23:50 PDT 2008


Known limitation until state methods are hoisted into the parent.   
Note this is impossible to do in the general case because as Max  
observed we allow placement on states so that the parent to hoist into  
may not be determined until runtime.

The issue is that state methods are not yet methods, so implicit this  
does not work.

The only work-around I can think of is for the compiler to insert  
`with(this)` for these non-methods, but for us to do that, we have to  
solve the swf9 generator but that prevents it from renaming locals (so  
they do not get shadowed by the `with(this)`.

On 2008-04-02, at 18:16 EDT, Henry Minsky wrote:
> I got this error when compiling a test app that uses <dragstate>
>
>
>  <view id="foo" bgcolor="0xcccccc"
>        x="100" y="100"
>        height="200" width="200"
>        onmousedown="dragger.apply()"
>        onmouseup="dragger.remove()">
>    <dragstate name="dragger"/>
>  </view>
>
>
> Compiler error: at 38 [/tmp/lzswf9/lzgen22136/$lzc$class_dragstate.as:
> 18]: Error: Call to a possibly undefined method __dragstate_getnewpos.
>
> this.setAttribute("x", this.drag_axis == "both" || this.drag_axis ==
> "x" ? __dragstate_getnewpos("x", this.immediateparent.getMouse("x") +
> this.__dragstate_xdoffset) : this.x)
>                                                                           ^
>
> Compiler error: at 29 [/tmp/lzswf9/lzgen22136/$lzc$class_dragstate.as:
> 22]: Error: Call to a possibly undefined method __dragstate_getnewpos.
>
> this.setAttribute("y", this.drag_axis == "both" || this.drag_axis ==
> "y" ? __dragstate_getnewpos("y", this.immediateparent.getMouse("y") +
> this.__dragstate_ydoffset) : this.y)
>                                                                           ^
>
>
> In lps/components/utils/states/dragstate.lzx, the definition of the x
> and y attribute constraints looks like this
>
>
>    <attribute name="x"
>       value="(this.drag_axis == 'both' || this.drag_axis == 'x') ?
>              __dragstate_getnewpos('x',
>                this.immediateparent.getMouse( 'x' ) +
> this.__dragstate_xdoffset)
>           : this.x"
>        when="always"/>
>
> If I change that function call to have "this.",
> "this.__dragstate_getnewpos", then it compiles without complaining.
>
> -- 
> Henry Minsky
> Software Architect
> hminsky at laszlosystems.com



More information about the Laszlo-dev mailing list