Recent News

AS2 to AS3 migration of FMS2 Chat application

Posted by sortofme on March 3rd, 2008

While I was trying to migrate a textChat application written in AS2 to AS3, I encountered the problem, that I couldn't use

Actionscript:
  1. nc.msgFromSrvr = function (msg) {
  2. chatPrintDebug ("msgFromSrvr "+msg);

as because the reference nc.msgFromSrvr does not work this way anymore.
I found a way on the Adobe Forums suggesting this way:

Actionscript:
  1. var connection = new NetConnection();
  2. connection.client = this;
  3. connection.connect("rtmp://localhost/application", "userName");
  4.  
  5. var remoteUsers = new SharedObject();
  6. remoteUsers = SharedObject.getRemote("users_so",connection.uri,false);
  7. remoteUsers.connect(connection);
  8. remoteUsers.client=this;
  9.  
  10. function msgFromSrvr (msg:String) { trace(msg); };

In the server-side I wrote the next code:

Actionscript:
  1. application.onAppStart = function () { application.users_so = SharedObject.get("users_so",false); }
  2. application.onConnect = function (userName) { application.users_so.send("msgFromSrvr","message_txt"); }

It worked fine.

passing parameters to Events, custom events

Posted by sortofme on February 29th, 2008

In AS 3.0, if you do want to pass params in your Events you can create your own custom events:

Actionscript:
  1. package{
  2.  
  3. import flash.events.Event;
  4.  
  5. class CustomEvent extends Event{
  6.  
  7. public static const MOUSE_DOWN:String = "onMouseDown";
  8.  
  9. public var myString:String;
  10.  
  11. public function CustomEvent( type:String, str:String ){
  12. myString = str;
  13. super( type );
  14. }//...
  15.  
  16. /*_______you then dispatch this like this______*/
  17.  
  18. //in hboxvar
  19. //you would have to import your custom event
  20. dispatchEvent( new CustomEvent( CustomEvent.MOUSE_DOWN, "1,2,3") )
  21.  
  22. //again you would need to import your custom event
  23. hboxvar.addEventListener( CustomEvent.MOUSE_DOWN, dosomething );
  24.  
  25. private function dosomething( event:CustomEvent ):Void{
  26. trace( event.myString ) // output: 1,2,3
  27. }

another interesting approach can be found here, where flep assigns multiple event types to one custom event, to have more variety in eventHandling.

But probably the most flexible of solutions is to add to the custom Event an Array, as Parameter, alllowing multiple parameters to be passed on when dispatched.

comment: display CustomEvent class 

AS3 textFields

Posted by sortofme on February 26th, 2008

TextFields are created in AS3 basically like most other objects, by first defining and then instantiating them:

Actionscript:
  1. </code>
  2.  
  3. package {
  4. import flash.display.Sprite;
  5. import flash.text.*;
  6. public class whynot extends Sprite{
  7. private var display_txt:TextField;
  8.  
  9. public function whynot(){
  10. display_txt = new TextField();
  11. display_txt.text = "a text";
  12. addChild(display_txt);
  13. }
  14. }
  15. }

Here the code of a function I use for creating my textfields. still basic, but displays the most common settings needed for your dynamic textField. assumingyou have a font added in the library with the class instance name "_tahoma":

Actionscript:
  1. private function makeTextField():void {
  2.  
  3. var tahoma:Font = new _tahoma();
  4.  
  5. TFFormat = new TextFormat();
  6.  
  7. TFFormat.font =tahoma.fontName;
  8. TFFormat.color = "0xFFFFFF";
  9. TFFormat.size = 11;
  10.  
  11. TextField = new TextField();
  12. TextField.width = 200;
  13. TextField.height = height;
  14. TextField.x = 42;
  15. TextField.y = 10;
  16. TextField.wordWrap = true;
  17. TextField.selectable = false;
  18. TextField.border = true;
  19. TextField.multiline = false;
  20. TextField.embedFonts = true;
  21. TextField.autoSize = TextFieldAutoSize.LEFT;
  22. TextField.antiAliasType = AntiAliasType.ADVANCED;
  23.  
  24. addChild(alertTextField);
  25.  
  26. alertTextField.setTextFormat(alertTFFormat);
  27.  
  28. };

One issue I discovered that I can't really explain, is that I often have to reassign the textFormat to the TextField when changing the fields content:

Actionscript:
  1. alertTextField.text = myString;
  2. alertTextField.setTextFormat(alertTFFormat);

setting the focus on an input field:

http://livedocs.adobe.com/flex/201/langref/flash/display/Stage.html#focus

in AS3, it's now a property rather than a function that you call. Also, you don't use the text name value of the field, but a reference to the actual field itself...

would look something like:

Actionscript:
  1. myObj.stage.focus = myTextField;

Adobe new Flash CS3 plugin for AIR development

Posted by sortofme on February 26th, 2008

Adobe has launched AIR version 1 and Flex 3. After some time in Beta, this is now a final release. With it comes a new plugin for Flash CS3, that has to be downloaded for developing AIR application within the Flash IDE.

wordpress syntax highlighting

Posted by sortofme on February 26th, 2008

My search for a good and easy syntax highlighter for my Wordpress blog, made me decide for iG:Syntax Hiliter from here

anpther one that seemed quite interesting and newer I found here: http://code.google.com/p/syntaxhighlighter/ which I haven't tryed, but if I do encounter any problems with iG:Syntax Hiliter.

more to come ...

AS3 MouseEvents and Buttons

Posted by sortofme on February 22nd, 2008

first off the link to the class documentation on Adobe Livedocs/MouseEvents:

Actionscript:
  1. //simple way of creating a default Button
  2. package{
  3.    import flash.display.MovieClip;
  4.    import flash.events.MouseEvent;
  5.    public class NavButton extends MovieClip {
  6.       public function NavButton() {
  7.       this.mouseEnabled = true;//to display the hand cursor on Rollover
  8.       this.buttonMode = true;
  9.       this.addEventListener(MouseEvent.ROLL_OVER, dim);
  10.       this.addEventListener(MouseEvent.ROLL_OUT, bright);
  11.       }
  12.       private function  dim ( event:MouseEvent ) : void{
  13.          this.alpha= .75;
  14.       }
  15.       private function bright(event:MouseEvent):void{
  16.          this.alpha = 1;
  17.       }
  18.    }
  19. }

a simple text chat

Posted by sortofme on February 21st, 2008

code collection for a simple text chat running through the flash media server 2, written in AS3.

AS3 cheat sheet

Posted by sortofme on February 21st, 2008

In my quest to convert my apps from AS2 to AS3, I tumbled across this very helpful cheat sheet:  AS2 to AS3 migration

more to be found here: www.actionscriptcheatsheet.com/

Recent Comments | Recent Posts


bottom