« November 2003 | Inicio | January 2004 »

December 30, 2003

My first jsfl (PublishAll)

Here's my first extension. A command that publishes all the open documents.

I know it's quite simple, but, well, you know, it's my first time...

Download PublishAll.mxp

December 29, 2003

Flexibility matters (AS2)

Yes, you guessed it, we can do something quite similar with the brand new AS 2.0

First of all, we’ll write a new class:

class net.designnation.exp.Dinamica{ public var prop1:String; public var prop2:String; public var prop3:String; function Dinamica(){ } public function metodo(Void):Void{ trace("method ------"); trace(prop1 + " " + prop2 + " " + prop3); } }

In the first frame of the main timeline, paste the following code:

import net.designnation.exp.*; var testClass:Dinamica = new Dinamica(); testClass.prop1 = "Hi!"; testClass["prop2"] = "I’m"; var cadena:String = "prop3"; testClass[cadena] = "testing"; //To retrieve tose values: for (var k=1;k<4;k++){ trace(testClass["prop"+k]); } //To execute the class method testClass.metodo(); //or testClass["metodo"](); //or var cadena2:String="metodo"; testClass[cadena2](); stop();

So, this is the way (at least one of the ways) to make one class method call another without even knowing it’s name, or to make one class call another one’s methods, ….

Anyway, this shows the power and flexibility of ActionScript.

Flexibility matters (AS1)

If we want to get or set any of the properties of an object, we can write something like this:

var miObj = new Object(); miObj.prop1 = "design-nation";

Although, we could have written something like:

var miObj = new Object(); miObj["prop1"] = "design-nation";

So, we can access an object properties dynamically, for example:

var miObj = new Object(); miObj.prop1 = "property1"; miObj.prop2 = "property2"; miObj.prop3 = "property3";

And we can retrieve those values like this:

for (var k=1;k<4;k++){ trace("prop"+k+ " = " + miObj["prop"+k]); }

But, what about the methods?. No problem. Let’s see:

var miObj = new Object(); miObj.metodo1 = function(){ trace("metodo1"); } miObj["metodo1"]();

That’s the way we can execute any given method of an object, without really knowing which one we are trying to access.

December 27, 2003

Tree component

Today, I've started to work in a new project where I need to use the new UI components

So, to test myself, I've made the little links thing that you can see on the right.

And I must say that everything has been fast and easy!:

_global.style.setStyle("fontSize", 12); myTree.setStyle("color", 0x999966); myTree.setStyle("borderStyle","solid"); myTree.setStyle("themeColor", "haloBlue"); // load and asign content myTreeDataProvider = new XML(); myTreeDataProvider.ignoreWhite = true; myTreeDataProvider.onLoad = function(){ myTree.dataProvider = myTreeDataProvider; } myTreeDataProvider.load("/enlaces/tree_en.xml"); myTreeListener = new Object(); myTreeListener.tree = myTree; myTreeListener.change = function(eventObject){ var theSelectedNode = eventObject.target.selectedNode; var theSelectedNodeLabel = theSelectedNode.attributes.label; var esLink = theSelectedNode.attributes.isLink; var esBranch = this.tree.getIsBranch(theSelectedNode) if (esBranch){ if (this.tree.getIsOpen(theSelectedNode)){ this.tree.setIsOpen(theSelectedNode, false, true); }else{ this.tree.setIsOpen(theSelectedNode, true, true); } }else{ if (esLink){ var theSelectedNodeURL = theSelectedNode.attributes.url; //trace("url " + theSelectedNodeURL); getURL(theSelectedNodeURL, "_blank"); } } } myTree.addEventListener("change", myTreeListener); stop();

The spanish version works also with the same swf.

Obviously the xml is generated as utf-8, so flash can display spanish and english characters.

And now I also have a Mac!!

:D

At last!. Here you can see my working place (it's friday, luch time, so that'a why there's so much activity).

But there it is. My new G4 with it's 21" monitor. The picture was taken with my girlfriend's mobile phone.

puesto.jpg

Gravity (source code)

So here it is, with it's wonderful spanish comments :|.

As you could see, this code could and should be optimized to make it not so proccessor.intensive.

Anyway, it's a good example of how we can build our applications without referencing _root.

When the main class is initialized:

var miGravedad:Gravedad = new Gravedad(this);

A reference to the timeline where the main class is located is passed to the class constructor. So we avoid any future trouble.

So, download the source code (of course, if you wish to)

Gravity

Drag the circle, and watch it falling (it's relaxing, isn't it?).

Well, it's not a completely accurate model, but.....






December 26, 2003

Experiment 3.0

Still looking for some inspiration:






Experiment 2.0

I'm still bored, so....






Let's experiment!

Today, I've started to work in a new game, so I've been trying to recover my lost math skills

Until now, I've only written two siple functions: one that returns the distance between two points, and another one return the orientation of the vector defined by two points. And then, it was when I started to get extremely bored, so it's when I started to play. And here you have the result:







The code it's not optimized, but it's the first swf posted here, so....

You can download the source code (with some wonderful comments in spanish)here.

December 21, 2003

fc components updater

Last days i have read this on a couple of blogs. Here you have a message on flashcom list where you can read what and what does not have this updater.

December 17, 2003

about MM releases

In the last couple of days, there have been a lot news about macromedia updaters o releases, here are some links

Flash player updater -> Macromedia

Updater flash video exporter y media components -> ash

Anunciado Flash Video Streaming Service -> peldi

December 14, 2003

bugs in FCS

Interesting article about bugs in flash communication server. Check it out. www.sti-media.com

December 13, 2003

Get the stats of your apps in flashcom

Here are two similar but a bit differents ways of get stats of your apps. both of them use a persisten Shared objet but, one get the global stats with application.getStats() and override the So, and the other one get the stats of each client session with clien.getStats() and add the values to the persisten SharedObject. You can use both in the same app

let's see the codes

Case one

application.onAppStart=function(){ //So onAppStart. there is created when the app starts the first time my_so=SharedObject.get("el_so",true); mis_stats={bytes_in:0, bytes_out:0, msg_in:0, msg_out:0, msg_dropped:0, total_connects:0, total_disconnects:0}; my_so.setProperty("appStats", mis_stats); }; application.onConnect=function(newClient){ application.acceptConnection(newClient); trace("new user"); }; application.onDisconnect=function(oldClient){ trace("User disconnected"); stats = application.getStats(); trace("Total bytes received: " + stats.bytes_in); trace("Total bytes sent : " + stats.bytes_out); trace("RTMP messages received : " + stats.msg_in); trace("RTMP messages sent : " + stats.msg_out); trace("RTMP messages dropped : " + stats.msg_dropped); trace("Total clients connected : " + stats.total_connects); trace("Total clients disconnected : " + stats.total_disconnects); //Give data to SO my_so.setProperty("appStats", stats); //force to save my_so.flush(); //Let´s check that all is ok //get so slot var the_stats=my_so.getProperty("appStats"); //see data on screen trace("check data"); for(var prop in the_stats){ trace(prop+" : "+the_stats[prop]); } };

the other way is

application.onAppStart=function(){ my_so=SharedObject.get("el_so",true); mis_stats={bytes_in:0, bytes_out:0, msg_in:0, msg_out:0, msg_dropped:0, ping_rtt:0}; my_so.setProperty("appStats", mis_stats); }; application.onConnect=function(newClient){ application.acceptConnection(newClient); trace("nuevo usuario conectado"); }; application.onDisconnect=function(oldClient){ trace("user disconnected"); stats = oldClient.getStats(); trace("Total bytes received : " + stats.bytes_in); trace("Total bytes sent : " + stats.bytes_out); trace("RTMP messages received : " + stats.msg_in); trace("RTMP messages sent: " + stats.msg_out); trace("RTMP messages dropped : " + stats.msg_dropped); trace("Ping roundtrip time: " + stats.ping_rtt); //Let´s add the stats of the session to the total stats //get so slot var the_stats=my_so.getProperty("appStats"); //add values for (var prop in the_stats){ the_stats[prop]=the_stats[prop]+stats[prop]; } //save my_so.setProperty("appStats", the_stats); //Force to save to disk my_so.flush(); //Let´s check //get SO data var comprobacion=my_so.getProperty("appStats"); //on screen trace("Comprobación de los datos"); for(var prop in comprobacion){ trace(prop+" : "+comprobacion[prop]); } };

and that's all. You must see the traces on your communciation app inspector. Te client side to this sample is only this.

nc=new NetConnection(); nc.onStatus=function(info){ trace(info.level); trace(info.code); } a.onRelease=function(){ nc.connect("rtmp:/test"); } b.onRelease=function(){ nc.close(); }

As always, sorry for my horrible english

December 12, 2003

AudioVideoStreamer with Flashcom. First Approach

yesterday i was playing with flashcom, and i decided to do an simple audiovideostreamer. Here are the codes. As you see is a really simple example, but it can show how easy is to work and have results with flash communication server

//net connection nc=new NetConnection(); /* Function: onStatusTemplate Desc: onStatus function to netConnection and netStream params: info -> gets the info from the server NOTE: this function, (onStatusTemplate) is based in Kevin Towes one.You can find this on his book "Macromedia Flash Communication Server MX" ( pangaea newmedia inc ) page 449, apendix. E */ function onStatusTemplate(info){ info_array=info.code.split("."); trace("·······················Start the message"); trace(new Date()); trace("message received to object: "+info_array[0]); trace("LEVEL: "+info.level); trace("CODE: "+info.code); /*Here it comes the rest of the template. it's a really large code, so when i finish the entire app, i put it here to download */ } // NetConnection.prototype.onStatus=onStatusTemplate; NetStream.prototype.onStatus=onStatusTemplate; //Connect to server( below onStatus ) nc.connect("rtmp:/videolistado/videomusic"); /* Function: audioVideoStreamer Desc: Create objects of audiovideoStreamer class. It allows to play audios ( mp3 ) and videos ( flv ). It is defined as _global Params: streamName -> stream name videoObjectName -> video object name netConnectionName -> netconnection name soundmcName -> mc to control volume bufferTimeC -> stablish buffer */ _global.audioVideoStreamer=function(streamName, videoObjectName, netConnectionName, soundmcName, bufferTimeC){ //Asig. this.my_ns=streamName; this.my_video=videoObjectName; this.my_nc=netConnectionName; this.my_sound_mc=soundmcName; this.my_buffer=bufferTimeC; // this.my_ns=new NetStream(this.my_nc); this.my_video.attachVideo(this.my_ns); this.my_ns.setBufferTime(this.my_buffer); this.my_sound_mc.attachAudio(this.my_ns); this.soundControl=new Sound(this.my_sound_mc); this.soundControl.setVolume(50); }//audioVideostreamer /* Function: doPlay Desc: Starts to play the selected stream. note that is different the way we play a stream if it's an audio stream or a video stream Params: selectedStream -> selected stream selectedType -> 2 possible values, "flv" or "mp3" */ audioVideoStreamer.prototype.doPlay=function(selectedStream,selectedType){ if(selectedType=="flv"){ this.my_ns.play(selectedStream); }//flv else if(selectedType=="mp3"){ this.my_ns.play("mp3:"+selectedStream); }//mp3 };//doPlay /* Function: doRewing Desc: rewing 10 seconds the stream Params: no params */ audioVideoStreamer.prototype.doRewing=function(){ this.my_ns.seek(this.my_ns.time-10); };//doRewing /* Function: doForward Desc: forwar 10 seconds the stream Params: no params */ audioVideoStreamer.prototype.doForward=function(){ this.my_ns.seek(this.my_ns.time+10); };//doForward /* Function: doPause Desc: pause the stream Params: no params */ audioVideoStreamer.prototype.doPause=function(){ this.my_ns.pause(); };//doPause /* Function: doDisconnect Desc: Finish the stream Params: no params */ audioVideoStreamer.prototype.doDisconnect=function(){ this.my_ns.play(false); this.my_ns.clear(); };//doDisconnect //////////////////////////USE of this this.createEmptyMovieclip("mi_mc", 1); reproductor=new audioVideoStreamer(el_stream, my_video, nc, mi_mc, 2); video1={label:"Macromedia", data:"video macromedia", typeF:"flv"}; musica1={label:"Bob & Marcia", data:"young gifted and black", typeF:"mp3"}; mis_Streams=[video1, musica1]; my_lb.setDataProvider(mis_Streams); my_lb.setChangeHandler("elegir", this); elegir=function(c){ selectedStream=c.getSelectedItem().data; selectedType=c.getSelectedItem().typeF; _root.reproductor.doPlay(selectedStream, selectedType); }; stop_btn.onRelease=function(){ reproductor.doDisconnect(); }; pause_btn.onRelease=function(){ reproductor.doPause(); }; rewing_btn.onRelease=function(){ reproductor.doRewing(); }; forward_btn.onRelease=function(){ reproductor.doForward(); };

of course i have on the screen an video object: my_video, a listbox component: my_lb and buttons.: stop_btn, pause_btn, rewing_btn, forward_btn

It will continue...

As always, sorry for my terrible english :(

December 10, 2003

A little game in Flashcom

It's true, that the most amazing feature of Flashcom is his poweful video and audio streaming, but , i think that the real power of flashcom is in sharedobjects. Here you are a really simple app to show the power of SO and syncro between conected users.

It is a simple "3 on line". Of course, it can be really improved, but it is just a test

//Initial values·········································· //I use 6 mc's, they are circles with two frames, one frame is a red circle //("rojo") and the other frame is a black circle ( "negro" ) circulo1={mc:circulo1_mc, x:40, y:235, color:"rojo" };//first circle circulo2={mc:circulo2_mc, x:20, y:194, color:"rojo" };//second circle circulo3={mc:circulo3_mc, x:40, y:152, color:"rojo" }; circulo4={mc:circulo4_mc, x:20, y:110, color:"negro"}; circulo5={mc:circulo5_mc, x:40, y:69, color: "negro" }; circulo6={mc:circulo6_mc, x:20, y:27, color: "negro" }; //array var circulos=[circulo1,circulo2,circulo3,circulo4,circulo5,circulo6]; //Zone flashcom········································· function initSO(nc){ //We build a non persistent SO my_so=SharedObject.getRemote("tresraya_so",nc.uri,false); my_so.onSync=function(lista){ for ( var prop in my_so.data){ debug("propiedad:valor - > "+prop+" : "+my_so.data[prop]); } var indexe=my_so.data.props[0]; var xPos=my_so.data.props[1]; var yPos=my_so.data.props[2]; circulos[indexe].mc._x=xPos; circulos[indexe].mc._y=yPos; } my_so.connect(nc); } //Conexión al servidor Flash Communication Server nc=new NetConnection(); nc.onStatus=function(info){ if(info=="NetConnection.Connect.Success");{ debug("estoy conectado"); initSO(this); } } nc.connect("rtmp:/tresenraya"); //functins·····························3 //trace function debug(texto){ trace(texto); } /* *Metodo: estadoIncial *Desc: establish the initial values and colors * *params: No params. */ estadoInicial=function(){ for (var i=0;i

A simple code, but it works and it can be used to show the power of So. You can improve it, i.e. makin the SO persistent on the Server, so you can "save match".