FlashComGuru Home InfluxisCDNImediaseeUvault
                                                                                       Forum Index | Active Topics | Register
                                                                                                          List Overview | List Archives
                                                                                                                           About this site | Advertise
 

home

Adobe AIR (11)
Applications (40)
Books & Training (11)
Collaboration (18)
Components (10)
Events (80)
Flash Player (35)
Flex (39)
FMS (110)
General (123)
Hosting (6)
Jobs (17)
Off topic (36)
OSMF (3)
Press Releases (23)
Site Check (11)
Tools (53)
Videos & Players (74)

Follow me on Twitter

 
I've been playing with Flex (as you may have heard) and I thought to myself 'why not jump in at the deep end and build something that works with Flash Media Server'. What I came up with (and what is work in progress) is this Flex audio chat app. Basically a text chat application which also support push to talk functionality - no video right now, just audio and text.

I've learnt a lot from building this, most notably:

  • There is now a client property for objects such as NetConnection and SharedObject, you need this to tell Flex where to direct callback methods to (so there's no more nc.doThis() - oh no). Thanks Owen
  • To make individual properties in an AS3 class bindable use custom events for each property. Something like
    [Bindable (ChangeEvent='histChange')]
    public var chatHistory:String = ""
    Thanks Johannes, you are the official Bindings-meister (no, not bondage!), who btw hasn't blogged since October 4th ;-)
  • If you are using a custom MXML itemRenderer (I did for my userlist) and want to inject some conditional logic into it, override data's getter/setter (I did in usersRenderer.mxml but couldn't have doen it without Tink, the IM oracle and Community Experts Expert).
  • FIXED In order to get a TextArea component to scroll all the way to the bottom programmatically you need to some weird sh*t. One would have thought that verticalScrollPosition = textField.maxScrollV may do the trick but no - this.validateNow(); is needed also.
    BUT STILL: while the last line of text is now visible, the scrollbar won't go right down (see pic). What's going on there? Any ideas? (NOTE: this has now been fixed, check comments for details). Thanks to mr for the validateNow() guidance.


    So there you go, Flex with live audio, and no I have no idea how well it scales. BTW I am sharing the sources for the text version only - no audio right now as this may turn into a commercial project - sorry. But I do hope you learn a lot from my code and my mistakes, and the audio part should be fairly easy to add.

    Check out FlexAudioChat

Related Articles

Comments
[Add Comment]
You can get the Scroll Bar to work right with the following code:

<mx:TextArea id="txtChatBox" styleName="chatBox" editable="false" updateComplete="txtChatBox.verticalScrollPosition = txtChatBox.maxVerticalScrollPosition + 1;" width="100%" height="100%"/>

The code was taken from my Flex Chat example, http://renaun.com/flex2/red5/BasicChat.html
# Posted By Renaun Erickson | 11/22/06 9:56 PM
this is really great Stefan. the audio worked great for me. i love this app. flexguru is on the horizon for you.
# Posted By phil elias | 11/23/06 12:20 AM
I found a workaround to the scroll bug in Flash 8:
function scrollBug() {
myTextArea.vPosition = myTextArea.maxVPosition;
}
// when you update de content of the textArea:
myTextArea.doLater("_root", "scrollBug);
# Posted By Edu Blanco | 11/23/06 7:48 AM
thanks guys.

Renaun, I have used your tip to modify my ChatTextarea mxml component which extends TextArea. I added this to the constructor:

addEventListener("updateComplete", onUpdateComplete);

and this to a private function onUpdateComplete:
this.verticalScrollPosition = this.maxVerticalScrollPosition + 1;

Works a treat.
Many thanks.
# Posted By Stefan | 11/23/06 9:01 AM
Stephan, thanks more so much for this app. I have been trying to find a Flex2 /FMS2/AS3 chat example and spent days dealing with incompatibility issues between versions while I am still learning the basics. Considering I am quiet new to AS, could you very briefly point me to the proper class / methods in order to add a private message function where you select a user and send him a private text message?
# Posted By Stephane | 12/2/06 11:32 AM
hi Stephane,
sorry but your question is a little complex to explain in a blog comment. I hope you'll figure it out yourself. Check the tutorial section for an article on private messages though.
# Posted By Stefan | 12/4/06 9:53 AM
Hey Stefan,    
I live in Brazil and am learning Flex 2,0 and FMS now, I would like to know if you have as to order the code to me I to study, with the audio one in functioning, congratulations for the great content!
# Posted By Carlos Eduardo | 12/18/06 12:25 AM
Hi Carlos,
are you wanting to buy the source files for the Flex Audiochat?
# Posted By Stefan | 12/18/06 9:19 AM
Hi Stefan,

I was thinking on adding the audio part to your text-chat, but I have some doubts.
I know netstream is one side only, if you talk you can't hear, so I suposse you must define, at least, two stremas, one for listen and one for talk, but... how can all users talk and listen each other? Have you to open one stream for each user to talk and connect any other users to these streams to listen?
All the samples I have found use comm components from flash ide, but I need to make this on flex, so these does not help me.

Thanks,
Jesus
# Posted By Jesus | 12/18/06 10:05 AM
to let each user hear himself you can use the mic loopback.
In order to let each user hear every other user I simply create a new NetStream for each user who is currently speaking.

So every user who speaks sends one stream. Every listener opens one stream per for each broadcasting user.
# Posted By Stefan | 12/18/06 10:25 AM
Hi and thanks Stefan,

That was what I was thinking but I have another doubt about performance.

on client, what happens when you got i.e. 30 users? each user has to subscribe to 29 streams.
and on server? 30*29=870!!! connections.

have you made any test?

Thanks again,
Jesus
# Posted By Jesus | 12/18/06 11:19 AM
no I haven't tested this but it a normal setup and you are right, it does not scale well. However it is fairly easy to restrict audio broadcasts to a certain number of users or allow each user to only listen to one stream at a time. These are details that you could implement.
My particular application is not likely to be popular enough to suffer from this problem however.
# Posted By Stefan | 12/18/06 11:35 AM
Where are the streams in the code? I couldn't even find a reference to the microphone
# Posted By Michael Mittelman | 5/7/07 6:26 PM
Michael, well spotted!
I messed up somehow - why has nobody noticed this before?
My old code from this app has been refactored so this class I post now *should* work but I cannot say for sure that it will... In any case it has the stream references in it. No idea what happened to the original, correct class...
http://www.flashcomguru.com/apps/flex/flexaudiocha...
# Posted By Stefan | 5/7/07 9:01 PM
You're up to saving my life with it - I've to do almost the same thing ( - unfortunately with snd and vid...

If you're on this topic, don't you know that how to stream the video of an IP cam via flash? Does it have 'hacks in it' or is it as easy as... very easy...

Thx for your answer

Respect++ for this code, ifrozen
# Posted By ifrozen | 6/30/07 12:56 PM
I couldn't make the audio work... :( Any ideas about what could be wrong???
# Posted By Andreina | 7/3/07 3:01 PM
many thanks for the TextArea scroll!
# Posted By veso | 1/2/08 1:31 AM
Hello,

St
# Posted By massimux | 1/11/08 4:07 PM
Hello,

Use your flex audio chat, but I can not quite make it to work.
I wanted to ask so if you could help me because they are the first steps with flex.

Thanks.
sorry for my bad english
# Posted By massimux | 1/11/08 4:09 PM
How do you make the text chat persistent? I tried changing the values from false to true in the server main chat_so and client on getRemote and that did not work. Got any ideas?
# Posted By Mike | 2/3/08 1:38 PM
another method to fix problem with textarea

is - call validateNow();
# Posted By disav | 4/28/08 9:28 AM
Hello,

I have tried to integrate your text chat with Renaun Erickson conference app for my class project, but since this is my first time using flex/fms/as, it turned to be a disaster. I am interested in purchasing the code so please contact me when you get a chance.

Thank you
# Posted By Ivana | 7/3/08 8:18 AM
Hello Stefan

I am interested in an audio/text chat only.
I read your post and would like to know how we can use it for our small company. Rent or buy... Can we discuss and are you interested?.. I am looking into various chat apps and yours, on its face, appears to fit our needs. I would only need to ask some questions, if you are amenable.

Thank you!
Ana
# Posted By ana | 10/22/08 3:01 PM
another happy taker of the scrollbar solution - using sdk 3.3. will it be fixed in 4.0?
# Posted By Kaspar | 7/12/09 11:14 PM