While I was trying to migrate a textChat application written in AS2 to AS3, I encountered the problem, that I couldn't use
Actionscript:
-
nc.msgFromSrvr = function (msg) {
-
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:
-
var connection = new NetConnection();
-
connection.client = this;
-
connection.connect("rtmp://localhost/application", "userName");
-
-
var remoteUsers = new SharedObject();
-
remoteUsers = SharedObject.getRemote("users_so",connection.uri,false);
-
remoteUsers.connect(connection);
-
remoteUsers.client=this;
-
-
function msgFromSrvr (msg:String) { trace(msg); };
In the server-side I wrote the next code:
Actionscript:
-
application.onAppStart = function () { application.users_so = SharedObject.get("users_so",false); }
-
application.onConnect = function (userName) { application.users_so.send("msgFromSrvr","message_txt"); }
It worked fine.
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:
-
package{
-
-
import flash.events.Event;
-
-
class CustomEvent extends Event{
-
-
public static const MOUSE_DOWN:String = "onMouseDown";
-
-
public var myString:String;
-
-
public function CustomEvent( type:String, str:String ){
-
myString = str;
-
super( type );
-
}//...
-
-
/*_______you then dispatch this like this______*/
-
-
//in hboxvar
-
//you would have to import your custom event
-
dispatchEvent( new CustomEvent( CustomEvent.MOUSE_DOWN, "1,2,3") )
-
-
//again you would need to import your custom event
-
hboxvar.addEventListener( CustomEvent.MOUSE_DOWN, dosomething );
-
-
private function dosomething( event:CustomEvent ):Void{
-
trace( event.myString ) // output: 1,2,3
-
}
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
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:
-
</code>
-
-
package {
-
import flash.display.Sprite;
-
import flash.text.*;
-
public class whynot extends Sprite{
-
private var display_txt:TextField;
-
-
public function whynot(){
-
display_txt = new TextField();
-
display_txt.text = "a text";
-
addChild(display_txt);
-
}
-
}
-
}
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:
-
private function makeTextField():void {
-
-
var tahoma:Font = new _tahoma();
-
-
TFFormat = new TextFormat();
-
-
TFFormat.font =tahoma.fontName;
-
TFFormat.color = "0xFFFFFF";
-
TFFormat.size = 11;
-
-
TextField = new TextField();
-
TextField.width = 200;
-
TextField.height = height;
-
TextField.x = 42;
-
TextField.y = 10;
-
TextField.wordWrap = true;
-
TextField.selectable = false;
-
TextField.border = true;
-
TextField.multiline = false;
-
TextField.embedFonts = true;
-
TextField.autoSize = TextFieldAutoSize.LEFT;
-
TextField.antiAliasType = AntiAliasType.ADVANCED;
-
-
addChild(alertTextField);
-
-
alertTextField.setTextFormat(alertTFFormat);
-
-
};
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:
-
alertTextField.text = myString;
-
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:
-
myObj.stage.focus = myTextField;
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.
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 ...
Posted by sortofme on February 22nd, 2008
first off the link to the class documentation on Adobe Livedocs/MouseEvents:
Actionscript:
-
//simple way of creating a default Button
-
package{
-
import flash.display.MovieClip;
-
import flash.events.MouseEvent;
-
public class NavButton extends MovieClip {
-
public function NavButton() {
-
this.mouseEnabled = true;//to display the hand cursor on Rollover
-
this.buttonMode = true;
-
this.addEventListener(MouseEvent.ROLL_OVER, dim);
-
this.addEventListener(MouseEvent.ROLL_OUT, bright);
-
}
-
private function dim ( event:MouseEvent ) : void{
-
this.alpha= .75;
-
}
-
private function bright(event:MouseEvent):void{
-
this.alpha = 1;
-
}
-
}
-
}
Posted by sortofme on February 21st, 2008
code collection for a simple text chat running through the flash media server 2, written in AS3.
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