I am using flash builder to build a flex project, and I am just getting into mxml
. I have a flash game that I made in Flash Professional CC - I published an swc
file from Flash CC - all of the symbols are exported in 1st frame, and exported for actionscript (in Symbol Properties) - They reside in the same folder as the swc
file.
In Flash Builder 4.6 - I added the swc
file to the library path so that I could access the symbols. Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<!-- <s:VGroup>
<s:TextArea id="textArea" width="300" height="300"/>
<s:Button label="Connect" click="onConnectClick()"/>
<s:Button label="Send" click="onSendClick()"/>
<s:Button label="Disconnect" click="onDisconnectClick()"/>
</s:VGroup> -->
<fx:Script>
<![CDATA[
import Avatar;
import Enemy;
import flash.display.*;
import com.adobe.serialization.json.JSON;
import com.hurlant.util.der.Integer;
import io.socket.flash.ISocketIOTransport;
import io.socket.flash.ISocketIOTransportFactory;
import io.socket.flash.SocketIOErrorEvent;
import io.socket.flash.SocketIOEvent;
import io.socket.flash.SocketIOTransportFactory;
import io.socket.flash.WebsocketTransport;
import io.socket.flash.XhrPollingTransport;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.system.Security;
private var _socketIOTransportFactory:ISocketIOTransportFactory = new SocketIOTransportFactory();
private var _ioSocket:ISocketIOTransport;
Security.loadPolicyFile("xmlsocket://localhost:10843");
private function onConnectClick():void
{
_ioSocket = _socketIOTransportFactory.createSocketIOTransport(XhrPollingTransport.TRANSPORT_TYPE, "localhost:8000/socket.io", this);
_ioSocket.addEventListener(SocketIOEvent.CONNECT, onSocketConnected);
_ioSocket.addEventListener(SocketIOEvent.DISCONNECT, onSocketDisconnected);
_ioSocket.addEventListener(SocketIOEvent.MESSAGE, onSocketMessage);
_ioSocket.addEventListener(SocketIOErrorEvent.CONNECTION_FAULT, onSocketConnectionFault);
_ioSocket.addEventListener(SocketIOErrorEvent.SECURITY_FAULT, onSocketSecurityFault);
_ioSocket.connect();
}
private function onSocketConnectionFault(event:SocketIOErrorEvent):void
{
trace(event.type + ":" + event.text);
}
private function onSocketSecurityFault(event:SocketIOErrorEvent):void
{
trace(event.type + ":" + event.text);
}
private function onDisconnectClick():void
{
_ioSocket.disconnect();
}
private function onSocketMessage(event:SocketIOEvent):void
{
if (event.message is String)
{
trace(String(event.message));
}
else
{
trace(com.adobe.serialization.json.JSON.encode(event.message));
}
}
private function onSendClick():void
{
_ioSocket.send({type: "chatMessage", data: "Привет!!!"});
_ioSocket.send({type: "chatMessage", data: "Delirium tremens"});
_ioSocket.send("HELLO!!!");
}
private function onSocketConnected(event:SocketIOEvent):void
{
//logMessage("Connected" + event.target);
trace("connected");
}
private function onSocketDisconnected(event:SocketIOEvent):void
{
//logMessage("Disconnected" + event.target);
trace("disconnected");
}
/*private function logMessage(message:String):void
{
textArea.text = textArea.text + message + "\n";
}*/
public function init():void {
var enemy:Enemy = new Enemy();
var avatar:Avatar = new Avatar();
var gameTimer:Timer;
myGroup.addChild(enemy);
myGroup.addChild(avatar);
avatar.x = mouseX;
avatar.y = mouseY;
gameTimer = new Timer( 25 );
gameTimer.addEventListener( TimerEvent.TIMER, onTick );
gameTimer.start();
function onTick( timerEvent:TimerEvent ):void
{
enemy.moveDownABit();
avatar.x = mouseX;
avatar.y = mouseY;
var score:int;
if ( avatar.hitTestObject( enemy ) )
{
score = gameTimer.currentCount;
gameTimer.stop();
}
}
}
]]>
</fx:Script>
<s:Group id="myGroup" width="400" height="300" initialize="init();"/>
</s:Application>
I have no errors, but it comes up as a blank page (it is a game where there is an avatar and an enemy - and the avatar tries to avoid the enemy as it moves down the screen).
What am I doing wrong? Do I need to embed the swf
file for the game too?
Also - you can ignore all of the socket stuff - that all works fine (I have already tested it, but I am trying to integrate socket.io-flash with my game). Thanks.