Hello. Please help me. simple example not works for me (((
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
creationComplete="application1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
private var eee:test123;
protected function application1_creationCompleteHandler(event:FlexEvent):void {
eee = new test123(this);
}
protected function button1_clickHandler(event:MouseEvent):void {
dispatchEvent( new Event("test2"));
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:Label text="{eee.text}"/>
<s:Button click="button1_clickHandler(event)"/>
</s:Application>
and file test123.as
package {
import flash.events.Event;
import flash.events.EventDispatcher;
import mx.binding.utils.BindingUtils;
public class test123 extends EventDispatcher{
[Bindable(event = "test1")]
public var text:String ;
public function test123(obj:EventDispatcher){
obj.addEventListener("test2",ontest2);
}
protected function ontest2(event:Event):void {
text = "fdsfadsf";
dispatchEvent(new Event("test1"));
}
}
}
When i clicked the button label not changes. But if i transfer all code from test123 directly to main program it works fine. What is wrong???
I don’t see Re: Cant understand why binding not works metadata in the example that is not working.
Also have a look please. Ive changed test123 class to something like singletone.
And it working without external binding. Why???
Main class:
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
creationComplete="application1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function application1_creationCompleteHandler(event:FlexEvent):void {
}
protected function button1_clickHandler(event:MouseEvent):void {
dispatchEvent( new Event("test2"));
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:Label text="{test123.getInstance(this).lalala()}"/>
<s:Button click="button1_clickHandler(event)"/>
</s:Application>
test123 class:
package {
import flash.events.Event;
import flash.events.EventDispatcher;
import mx.binding.utils.BindingUtils;
public class test123 extends EventDispatcher{
private var text:String ;
private static var instance:test123 = null;
public static function getInstance(obj:EventDispatcher):test123{
if (!instance) instance = new test123(obj);
return instance
}
public function test123(obj:EventDispatcher){
obj.addEventListener("test2",ontest2);
}
[Bindable(event = "test1")]
public function lalala():String {
return text;
}
protected function ontest2(event:Event):void {
text = "fdsfadsf";
dispatchEvent(new Event("test1"));
}
}
}
Why it working now?
The main problem - Ive the same code with singletone in my live application. And sometimes lalala is not fired update. And i dont know why???
Thanks for explanations. Seems good for me.
I started with this investigation once faced binding issue in my code. Can you have a look?
1 Ive callback from server
public function onUserStateChanged(userId:Number,state:int) :void{
Cc.log(" *** onUserStateChanged "+userId+","+state);
CommonModel.getInstance().messageTarget.dispatchEvent(new DynamicEvent(Events.USER_STATE_CHANGED, false, false, [userId,state]));
}
2 This messages is accepted in my signletone
addEventListener("refreshUserState",onTest);
CommonModel.getInstance().messageTarget.addEventListener(Events.USER_S TATE_CHANGED,onUserStateChanged);
and then in code:
public function onUserStateChanged(event:DynamicEvent):void{
var userId:Number = event.eventData[0];
var state:Number = event.eventData[1];
var user:Object = findUserById(usersInCurrentConference,userId);
if (!user){
Cc.log(" !!! User not found while on user state changing for user "+userId+" !!!");
return;
}
user.state = state;
dispatchEvent(new Event("refreshUserState"));
}
In this class i ve also two additional methods:
private function onTest(event:Event):void{
trace ("fasdfasdf");
}
and
[Bindable (event = "refreshUserState")]
public function isUserDisconnected(user:Object):Boolean{
if (!user) return false;
return user.state == User.STATUS_DISCONNECTED;
}
3 From external code ( list renderer ) which created after first access to singletone
<s:BorderContainer id="disconnectedMessageContainer" left="1" top="1" right="1" bottom="1" visible="{UserHelper.getInstance().isUserDisconnected(data)}" backgroundAlpha="0.6" backgroundColor="0x000000"
mouseChildren="false">
<s:HGroup width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
<s:Label color="0xffffff" text = "DISCONNECTED" fontWeight="bold"/>
</s:HGroup>
</s:BorderContainer>
And what i see. When calback comes onTest function fires with no problems. also in debug i see that refreshUserState fires also but disconnectedMessageContainer not refreshes. i can see in debug any requat to isUserDisconnected function.
What does it mean? Can you help and advise?
North America
Europe, Middle East and Africa
Asia Pacific