[FONT=Tahoma][SIZE=3]hey everybody,
I have a big deal here, and havent be able to solve it.
Im creating a flex chat, with php sockets and the AS3 xmlSocket class basically.
I have a main class Chat, there I stablish the connection, send and receive the messages. However, I have seen how it is possible to get access to a button or textArea from an AS script wrote in the main mxml file, I mean, something like this works clearly:
[/SIZE][/FONT] ActionScript Code:
[LEFT]<mx:Script><![COLOR=#000000][[/COLOR]CDATA[COLOR=#000000][[/COLOR]
[COLOR=#0000ff]private[/COLOR] [COLOR=#000000]function[/COLOR] setLabelCOLOR=#000000[/COLOR]:[COLOR=#0000ff]void[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]myButton.[COLOR=#000080]label[/COLOR]==[COLOR=#ff0000]“Click Me”[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
myButton.[COLOR=#000080]label[/COLOR] = [COLOR=#ff0000]“Clicked”[/COLOR];
[COLOR=#000000]}[/COLOR] [COLOR=#0000ff]else[/COLOR] [COLOR=#000000]{[/COLOR]
myButton.[COLOR=#000080]label[/COLOR] = [COLOR=#ff0000]“Click Me”[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]][/COLOR][COLOR=#000000]][/COLOR]></mx:Script>
<mx:[COLOR=#0000ff]Button[/COLOR] id=[COLOR=#ff0000]"myButton"[/COLOR] label=[COLOR=#ff0000]"Click Me"[/COLOR] click=[COLOR=#ff0000]"setLabel();"[/COLOR]/>
[/LEFT]
[FONT=Tahoma][SIZE=3]
[/SIZE][/FONT][LEFT][LEFT][LEFT]However, when I try to access the same way, but now from my class it does not recognize Im referencing a component at mx.core.Application. I have tried to pass the reference from the application to the class (just as you we do in Flash) but it doesnt work. So my problem is **How do I access mxml components in the main application from an ActionScript class **, I get the messages from the socket and I need to write them on a textArea.
This is how I import the class
ActionScript Code:
[LEFT]<mx:Script>
<![COLOR=#000000][[/COLOR]CDATA[COLOR=#000000][[/COLOR]
[COLOR=#0000ff]import[/COLOR] com.[COLOR=#000080]Chat[/COLOR];
[COLOR=#0000ff]public[/COLOR] [COLOR=#000000]function[/COLOR] initAppCOLOR=#000000[/COLOR]:[COLOR=#0000ff]void[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#000000]var[/COLOR] myChat = [COLOR=#000000]new[/COLOR] ChatCOLOR=#000000[/COLOR];
myChat.[COLOR=#0000ff]Connect[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]][/COLOR][COLOR=#000000]][/COLOR]>
</mx:Script>
[/LEFT]
And my classs:…
ActionScript Code:
[LEFT]package com [COLOR=#000000]{[/COLOR]
[COLOR=#0000ff]import[/COLOR] flash.[COLOR=#000080]events[/COLOR].*;
[COLOR=#0000ff]import[/COLOR] flash.[COLOR=#000080]net[/COLOR].[COLOR=#0000ff]XMLSocket[/COLOR];
[COLOR=#0000ff]public[/COLOR] [COLOR=#000000]**class**[/COLOR] Chat [COLOR=#000000]{[/COLOR]
[COLOR=#808080]*//private var hostName:String = "192.168.0.102";*[/COLOR]
[COLOR=#0000ff]private[/COLOR] [COLOR=#000000]**var**[/COLOR] hostName:[COLOR=#0000ff]String[/COLOR] = [COLOR=#ff0000]"192.168.0.123"[/COLOR];
[COLOR=#808080]*//private var hostName:String = "192.168.0.106";*[/COLOR]
[COLOR=#0000ff]private[/COLOR] [COLOR=#000000]**var**[/COLOR] port:uint = [COLOR=#000080]9999[/COLOR];
[COLOR=#0000ff]private[/COLOR] [COLOR=#000000]**var**[/COLOR] socket:[COLOR=#0000ff]XMLSocket[/COLOR];
[COLOR=#0000ff]private[/COLOR] [COLOR=#000000]**var**[/COLOR] usern:[COLOR=#0000ff]String[/COLOR]=[COLOR=#ff0000]""[/COLOR];
[COLOR=#0000ff]private[/COLOR] [COLOR=#000000]**var**[/COLOR] head:[COLOR=#0000ff]String[/COLOR],body:[COLOR=#0000ff]String[/COLOR], msg:[COLOR=#0000ff]String[/COLOR];
[COLOR=#0000ff]private[/COLOR] [COLOR=#000000]**var**[/COLOR] window;
[COLOR=#0000ff]public[/COLOR] [COLOR=#000000]**function**[/COLOR] Chat[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#808080]*//usern = "Xtian";*[/COLOR]
socket = [COLOR=#000000]**new**[/COLOR] [COLOR=#0000ff]XMLSocket[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
configureListeners[COLOR=#000000]([/COLOR]socket[COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#0000ff]public[/COLOR] [COLOR=#000000]**function**[/COLOR] setUsername[COLOR=#000000]([/COLOR]user[COLOR=#000000])[/COLOR]:[COLOR=#0000ff]void[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000ff]this[/COLOR].[COLOR=#000080]usern[/COLOR] = user;
[COLOR=#000000]}[/COLOR]
[COLOR=#0000ff]public[/COLOR] [COLOR=#000000]**function**[/COLOR] [COLOR=#0000ff]Connect[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]:[COLOR=#0000ff]void[/COLOR] [COLOR=#000000]{[/COLOR]
socket.[COLOR=#0000ff]connect[/COLOR][COLOR=#000000]([/COLOR]hostName, port[COLOR=#000000])[/COLOR];
msgArea.[COLOR=#0000ff]text[/COLOR] += [COLOR=#ff0000]"Connecting to server[COLOR=#000099]**
**[/COLOR]"[/COLOR];
…
[/LEFT]
The problem is right here!
ActionScript Code:
[LEFT]msgArea.[COLOR=#0000ff]text[/COLOR] += [COLOR=#ff0000]“Connecting to server[COLOR=#000099]**
**[/COLOR]”[/COLOR];
[/LEFT]
msgArea is a TextArea on the main Application.
Thanks for any help, I hope everything is clear
::Goto::
[/LEFT]
[/LEFT]
[/LEFT]