This is a general problem with constraints and events.  Constraints rely on an 
event being sent _at_least_ every time a value they depend on is changed.  But 
the system is free to optimize by sending events when there has not been a 
change, and to not send an event if a value is updated but does not change.  
This is a discussion we've had at length on laszlo-dev where I have tried to 
draw a distinction between constraints (which are built upon events) and 
events.  Constraints are very powerful, but they are not the only hammer in the 
toolbox.  If you need to ensure that an event is sent (or not sent) then you 
have to use <event> and <handler> directly.

I would say that this problem is a case where you need to do that, since the 
event that is sent when data_url gets its initial (undefined) value is 
interfering with the logic of the program.

On 2010-01-24, at 19:28, Henry Minsky wrote:

> Actually, I could use some suggestions on better ways to accomplish what
> Lucas is trying to do.
> 
> He has a canvas attribute called "data_url", and he wants a dataset to
> automatically make a new request whenever that value changes. He's trying to
> do that with a constraint
> 
>    <dataset id="perms"
>             name="perms"
>             type="http"
>             src="${canvas.data_url}"
>> 
> 
> I was going to suggest setting 'autorequest=true' on the dataset, so that
> it
> will fire automatically when the src attribute changes, but the problem is
> at startup,
> the constraint system sends an event for "data_url", before it  has
> a legitimate value. He's trying to set the value from a browser query arg,
> in the canvas
> oninit handler.
> 
> e.g.,
> 
> <method name="init">
>        canvas.prof = lz.Browser.getInitArg('prof');
>        if(canvas.prof) {
>            canvas.setAttribute('data_url','/trunk/xml/request_key/' +
> canvas.prof+".xml");
>        }
>    </method>
> 
> So the question is, is there any idiom  for disabling the event-sending
> action of a constraint until after the
> system has initialized? It seems to me like people would run into this in a
> lot of cases at
> app startup?
> 
> 
> 
> 
> 
> On Sun, Jan 24, 2010 at 6:00 PM, Lucas Lain <[email protected]> wrote:
> 
>> Hello Henry,
>> 
>> thank you very much for trying the code. I tried several things, and
>> realized that everythings works OK when I use the button (as in your
>> example).
>> 
>> But when I try to automatically execute the perms.doRequest on init, it
>> does not work.
>> 
>> Is  there a way to automatically execute perms.doRequest after finishing
>> loading?
>> Which is the best way of doing this.
>> 
>> Thank you very much.
>> 
>> Lucas.
>> 
>> On Sat, Jan 23, 2010 at 6:52 PM, Henry Minsky <[email protected]>wrote:
>> 
>>> Note, I am using the HttpFox plugin to trace the HTTP request from the
>>> Flash player
>>> 
>>> 2010/1/23 Henry Minsky <[email protected]>
>>> 
>>> I'm not able to reproduce the problem you are reporting.
>>>> 
>>>> I used the following test case
>>>> 
>>>> <canvas proxied="false" oninit="canvas.sprite.setBGColor(null);"
>>>> debug="true">
>>>> 
>>>>    <attribute name="prof" type="string" value=""/>
>>>>    <attribute name="data_url" type="string" value="BADVALUE"/>
>>>> 
>>>>    <method name="init">
>>>>        canvas.prof = lz.Browser.getInitArg('prof');
>>>>        if(canvas.prof) {
>>>>            canvas.setAttribute('data_url','/trunk/xml/request_key/' +
>>>> canvas.prof+".xml");
>>>>        }
>>>>    </method>
>>>> 
>>>>    <dataset id="perms"
>>>>             name="perms"
>>>>             type="http"
>>>>             autorequest='false'
>>>>             ondata="Debug.info(this.serialize())"
>>>>             src="${canvas.data_url}"
>>>>             />
>>>> 
>>>>    <button onclick="perms.doRequest()">dorequest</button>
>>>> 
>>>> </canvas>
>>>> 
>>>> 
>>>> and fetched it with the URL
>>>> 
>>>> http://127.0.0.1:8080/trunk/test/foo/player.lzx?prof=foo&debug=true&lzr=swf9
>>>> 
>>>> When I click the button, the correct request is issued, to
>>>> GET /trunk/xml/request_key/foo.xml?__lzbc__=1264279916554 HTTP/1.1
>>>> 
>>>> Does this test case work for you?
>>>> 
>>>> 
>>>> On Sat, Jan 23, 2010 at 1:43 PM, Lucas Lain <[email protected]>wrote:
>>>> 
>>>>> I renamed everything to prof_p, but still can make it to work.
>>>>> 
>>>>> Did anyone have a workaround for this?
>>>>> 
>>>>> I just want to send some information to the webserver from the
>>>>> flashclient.
>>>>> 
>>>>> Best.
>>>>> 
>>>>> L.
>>>>> 
>>>>> 
>>>>> 
>>>>> On Sat, Jan 23, 2010 at 11:04 AM, Henry Minsky 
>>>>> <[email protected]>wrote:
>>>>> 
>>>>>> One thing that is important, you should probably  use a different query
>>>>>> arg than "profile", because that has a special
>>>>>> meaning to the LPS server, it is used to enable the profiler  which is
>>>>>> used to meter performance.
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>>> Best.
>>>>>>> 
>>>>>>> L.
>>>>>>> 
>>>>>>> 
>>>>>>> On Fri, Jan 22, 2010 at 1:14 AM, Lucas Lain <[email protected]>wrote:
>>>>>>> 
>>>>>>>> Please see both attached files.
>>>>>>>> 
>>>>>>>> The perms.doRequest is called from the view inside play_button.
>>>>>>>> 
>>>>>>>> I'm using OL 4.7. The file is compiled to SWF9.
>>>>>>>> 
>>>>>>>> 
>>>>>>>> On Fri, Jan 22, 2010 at 1:04 AM, Henry Minsky <
>>>>>>>> [email protected]> wrote:
>>>>>>>> 
>>>>>>>>> Where do you actually call the doRequest() method on the dataset?
>>>>>>>>> Do you
>>>>>>>>> call it manually?
>>>>>>>>> 
>>>>>>>>> If  the dataset is set to make the  request automatically, e.g.,
>>>>>>>>> (the 'request' attribute == true) then
>>>>>>>>> the request might get made before the constraint updates.
>>>>>>>>> 
>>>>>>>>> Also, what runtime are you using?
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> On Thu, Jan 21, 2010 at 9:48 PM, Lucas Lain 
>>>>>>>>> <[email protected]>wrote:
>>>>>>>>> 
>>>>>>>>>> Hello Everybody,
>>>>>>>>>> 
>>>>>>>>>> I'm trying to set a dataset url dynamically. The thing is that the
>>>>>>>>>> dataset actually connects to the default data_url specified by 
>>>>>>>>>> default
>>>>>>>>>> ("/xml/request_key") and not the dynamic one ("/xml/request_key/" +
>>>>>>>>>> canvas.profile).
>>>>>>>>>> 
>>>>>>>>>> When I check the value in the debug console, the value is set to
>>>>>>>>>> the second, but actually connects to the first one.
>>>>>>>>>> 
>>>>>>>>>> When the oninit method is executed? after processing all ${}
>>>>>>>>>> values?
>>>>>>>>>> 
>>>>>>>>>> Thanks in advance!
>>>>>>>>>> 
>>>>>>>>>> code:
>>>>>>>>>> 
>>>>>>>>>> <canvas proxied="false" oninit="canvas.sprite.setBGColor(null);"
>>>>>>>>>> debug="true">
>>>>>>>>>> 
>>>>>>>>>>    <attribute name="profile" type="string" value=""/>
>>>>>>>>>>    <attribute name="data_url" type="string"
>>>>>>>>>> value="/xml/request_key/"/>
>>>>>>>>>> 
>>>>>>>>>>    <handler name="oninit">
>>>>>>>>>>        canvas.profile = lz.Browser.getInitArg('profile');
>>>>>>>>>>        if(canvas.profile) {
>>>>>>>>>>            canvas.setAttribute('data_url','/xml/request_key/' +
>>>>>>>>>> canvas.profile);
>>>>>>>>>>        }
>>>>>>>>>>    </handler>
>>>>>>>>>> 
>>>>>>>>>>    <dataset id="perms"
>>>>>>>>>>             name="perms"
>>>>>>>>>>             type="http"
>>>>>>>>>>             src="${canvas.data_url}"
>>>>>>>>>>             />
>>>>>>>>>> 
>>>>>>>>>> ...
>>>>>>>>>> 
>>>>>>>>>> --
>>>>>>>>>> Lucas
>>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> --
>>>>>>>>> Henry Minsky
>>>>>>>>> Software Architect
>>>>>>>>> [email protected]
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>> 
>>>>>>>> 
>>>>>>>> --
>>>>>>>> Lucas
>>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>> --
>>>>>>> Lucas
>>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> --
>>>>>> Henry Minsky
>>>>>> Software Architect
>>>>>> [email protected]
>>>>>> 
>>>>>> 
>>>>>> 
>>>>> 
>>>>> 
>>>>> --
>>>>> Lucas
>>>>> 
>>>> 
>>>> 
>>>> 
>>>> --
>>>> Henry Minsky
>>>> Software Architect
>>>> [email protected]
>>>> 
>>>> 
>>>> 
>>> 
>>> 
>>> --
>>> Henry Minsky
>>> Software Architect
>>> [email protected]
>>> 
>>> 
>>> 
>> 
>> 
>> --
>> Lucas
>> 
> 
> 
> 
> -- 
> Henry Minsky
> Software Architect
> [email protected]


Reply via email to