This topic will talk shortly about the stage class. When we create our new class and need to access to stage class (Main timeline) example "stage.stageWidth"we will see the error "cannot access to null property" or some thing else -*-.I use some easy tip to access to stage class .
code!
package
{
import flash.display.Stage;
public class flashBadass
{
private var __stage:Stage;
public functon flashBadass(st:Stage)
{
__stage=st;
trace(__stage.stageWidth);///easyly but for newbies you will headache with this problem.
}
}
}
On timeline when you create new instace of this class you must pass stage to the method.
import flashBadass;
var flBadass:flashBadass = new flashBadass(stage);
I dont know if you had other way to do please tell me.*-*
Hudsadin keox
Saturday, September 13, 2008
Thursday, September 04, 2008
Easy loading Xml with as3.0
This project will show you how to load data from Xml file.
Actionscript 3.0 help you work with xml more easier than actionscript 2.0 you will love it.
First create xml file like this

We will load this file store value of attributes "name" and value of "url" feilds.
Start Codding!
- Create new as file name loadXml.as and add this code.
var lxml:loadXml = new loadXml ("your xml path");
If you want to use the data you can access this variable "lxml.ImageNameArr" and lxml.ImageUrlArr.
You can implement this example to a flash image gallery or anything else.
easy job.
Hudsadin keox
Actionscript 3.0 help you work with xml more easier than actionscript 2.0 you will love it.
First create xml file like this

We will load this file store value of attributes "name" and value of "url" feilds.
Start Codding!
- Create new as file name loadXml.as and add this code.
packageOn main time line add tis code.
{
import flash.xml.*;
import flash.events.*;
import flash.net.*;
public class loadXml
{
public var ImageUrlArr:Array;
public var ImageNameArr:Array;
function loadXml(path:String)
{
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest(path));
}
function LoadXML(e:Event):void
{
var xmlData:XML = new XML ();
xmlData.ignoreWhite = true;
xmlData = new XML (e.target.data);
for (var k in xmlData.pic.url.attribute("name"))
{
ImageNameArr[k]=xmlData.pic.url.attribute("name")[k];
}
for (var i in xmlData.pic.url.text())
{
ImageUrlArr[i]=xmlData.pic.url.text()[i];
}
}
}
}
var lxml:loadXml = new loadXml ("your xml path");
If you want to use the data you can access this variable "lxml.ImageNameArr" and lxml.ImageUrlArr.
You can implement this example to a flash image gallery or anything else.
easy job.
Hudsadin keox
Wednesday, September 03, 2008
Fun with Tween Class and some combobox!
This topic will talk about how we can play with Tween Class from flash actionscript 3.0.
Labels:
actionscript,
as3.0,
combobox,
flash,
tween
Tuesday, September 02, 2008
How to Connect to socket as3.0.
I'm not real English native but I think you all will understand by read the code and some my suggestion.
First what is socket.
The Socket class enables ActionScript code to make socket connections and to read and write raw binary data. It is similar to XMLSocket but does not dictate the format of the received or transmitted data.
- create new as file
Save it name clientConnect.as
and add this code.
package
{
import flash.net.Socket;
import flash.events.Event;
import flash.events.ProgressEvent;
////////////////////////////////////////////////////////////// import some class that have to use for this project
public class clientConnect
{
private var client:Socket = new Socket();// instance of Socket class we will use this instace to connect to demon.
private var s_path:String = "";//variable for set server path .
private var s_port:uint;//variable for set server port .
private var returnData:uint;//variable for store data that client recive form server.
private var c_data:uint;//variable for store data that wee want to sent to server.
private var recived:Boolean=false;//variable for check client recived data yet.
public function clientConnect(path:String,port:uint)//when we define class variable and call this method we must sent serve path and port to this method.
{
s_path=path;
s_port=port;
}
public function connected()//sure this function try to connect to server*-*.
{
try
{
client.connect(s_path,s_port);
}
catch (e:ArgumentError)
{
trace(e);
}
client.addEventListener(Event.CONNECT,sentData);
client.addEventListener(ProgressEvent.SOCKET_DATA,reciveData);
}
public function setData(data_in:uint)//set data that we want to sent to server.
{
c_data = data_in;
}
private function sentData(evt:Event):void
{
client.writeInt(c_data);
}
public function getData():uint//when we need to use the data that server had sent to client call this function .
{
if(recived)
return returnData;
else
return null;
}
private function reciveData(evt:ProgressEvent)
{
returnData = client.readInt();
recived = true;
trace(returnData)
client.close();
}
}
}
Now we had finished the client codding.
next go to fun with some easy java code for demon!
you must have jdk download it!
- create new text file and save its name Server.java
- add this code
import java.io.*;
import java.net.*;
public class Server
{
public static void main(String args[])
{
while(true)
{
try{
ServerSocket serverSocket = new ServerSocket(1500); //new server socket instace that set port 1500 (flash client must set like this demon)
System.out.println("Please, wait....");
Socket clientSocket = serverSocket.accept(); //accepted client who connected to this port
System.out.println("Connected : "+clientSocket.getInetAddress().toString());
DataInputStream inData = new DataInputStream(clientSocket.getInputStream()); //instace for store data from client
DataOutputStream outData = new DataOutputStream(clientSocket.getOutputStream());//instace for sent data to client.
System.out.println("recive Data ...."+inData.readInt()+" and return Data 20");
outData.writeInt(20); //write 20 to flash client
clientSocket.close();
serverSocket.close();
}catch(IOException e)
{
e.printStackTrace();
break;
}
}
}
}
You can implement this bacsic socket project to make your own flash chat,mutiplayer game,
or some easy realtime msg sending.
Thank ! for visited this blog.
Hudsadin keox
First what is socket.
The Socket class enables ActionScript code to make socket connections and to read and write raw binary data. It is similar to XMLSocket but does not dictate the format of the received or transmitted data.
The Socket class is useful for working with servers that use binary protocols.
When you use this class, consider the Flash Player security model:
- Data loading is not allowed if the calling SWF file is in the local-with-file-system sandbox and the target resource is from a network sandbox.
- Data loading is also not allowed if the calling SWF file is from a network sandbox and the target resource is local.
- The calling SWF file and the network resource being accessed must be in exactly the same domain. For example, a SWF file at adobe.com can connect only to a server daemon at adobe.com.
- Websites can permit cross-domain access to a resource through a cross-domain policy file.
- create new as file

and add this code.
package
{
import flash.net.Socket;
import flash.events.Event;
import flash.events.ProgressEvent;
////////////////////////////////////////////////////////////// import some class that have to use for this project
public class clientConnect
{
private var client:Socket = new Socket();// instance of Socket class we will use this instace to connect to demon.
private var s_path:String = "";//variable for set server path .
private var s_port:uint;//variable for set server port .
private var returnData:uint;//variable for store data that client recive form server.
private var c_data:uint;//variable for store data that wee want to sent to server.
private var recived:Boolean=false;//variable for check client recived data yet.
public function clientConnect(path:String,port:uint)//when we define class variable and call this method we must sent serve path and port to this method.
{
s_path=path;
s_port=port;
}
public function connected()//sure this function try to connect to server*-*.
{
try
{
client.connect(s_path,s_port);
}
catch (e:ArgumentError)
{
trace(e);
}
client.addEventListener(Event.CONNECT,sentData);
client.addEventListener(ProgressEvent.SOCKET_DATA,reciveData);
}
public function setData(data_in:uint)//set data that we want to sent to server.
{
c_data = data_in;
}
private function sentData(evt:Event):void
{
client.writeInt(c_data);
}
public function getData():uint//when we need to use the data that server had sent to client call this function .
{
if(recived)
return returnData;
else
return null;
}
private function reciveData(evt:ProgressEvent)
{
returnData = client.readInt();
recived = true;
trace(returnData)
client.close();
}
}
}
At the main swf file add the code like this.
import clientConnect;
var client:clientConnect = new clientConnect("localhost",1500);
client.setData(100);//sent 100 te server.
client.connected();
import clientConnect;
var client:clientConnect = new clientConnect("localhost",1500);
client.setData(100);//sent 100 te server.
client.connected();
Now we had finished the client codding.
next go to fun with some easy java code for demon!
you must have jdk download it!
- create new text file and save its name Server.java
- add this code
import java.io.*;
import java.net.*;
public class Server
{
public static void main(String args[])
{
while(true)
{
try{
ServerSocket serverSocket = new ServerSocket(1500); //new server socket instace that set port 1500 (flash client must set like this demon)
System.out.println("Please, wait....");
Socket clientSocket = serverSocket.accept(); //accepted client who connected to this port
System.out.println("Connected : "+clientSocket.getInetAddress().toString());
DataInputStream inData = new DataInputStream(clientSocket.getInputStream()); //instace for store data from client
DataOutputStream outData = new DataOutputStream(clientSocket.getOutputStream());//instace for sent data to client.
System.out.println("recive Data ...."+inData.readInt()+" and return Data 20");
outData.writeInt(20); //write 20 to flash client
clientSocket.close();
serverSocket.close();
}catch(IOException e)
{
e.printStackTrace();
break;
}
}
}
}
You can implement this bacsic socket project to make your own flash chat,mutiplayer game,
or some easy realtime msg sending.
Thank ! for visited this blog.
Hudsadin keox
Labels:
actionscript,
chat,
flash,
multiplayer,
realtime,
socket
Subscribe to:
Posts (Atom)