PDA

View Full Version : Problem with AS3.0 in Flex Builder 3


CreITve
02-17-2009, 04:33 PM
Hi everyone, I recently started learning Flex/Air platform (like it much). Actually i'm new to AS3 too, so i've got a problem.
While learning how to use XMLSocket object i wrote this mxml code at Flex Builder 3 : (copy at pastebin for your corections (http://kefir.pastebin.com/m7605dc57))
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Button x="171" y="136" label="Button" width="264" height="63" click="init()"/>
<mx:Script>
<![CDATA[


import flash.net.XMLSocket;

var mySock:XMLSocket = new XMLSocket();
private function init():void
{

mySock.addEventListener(Event.CONNECT, connected);
mySock.addEventListener(DataEvent.DATA, dataReceived);
mySock.connect("localhost",8989);
}

private function connected(event:Event):void
{import flash.net.XMLSocket;
mySock.send("Hi");
}
private function dataReceived(dataEvent:DataEvent):void
{
trace(dataEvent.data);
var xml:XML = new XML(dataEvent.data);
}




]]>
</mx:Script>

</mx:WindowedApplication>


And before the running i got these errors:
Severity and Description Path Resource Location Creation Time Id
1061: Call to a possibly undefined method connect through a reference with static type XMLSocket. XMLSocket/src XMLSocket.mxml line 16 1234888871500 258
1061: Call to a possibly undefined method send through a reference with static type XMLSocket. XMLSocket/src XMLSocket.mxml line 21 1234888871515 259

I know it must be an "another n00b's stupid mistake", but forum is for asking, isn't it?;)

Peter Cowling
02-17-2009, 05:44 PM
Hello,

This example (http://livedocs.adobe.com/flex/3/langref/flash/net/XMLSocket.html) can be used to achieve what you are looking to do.

Note that the event listeners are configured in a function that takes in IEventDispatcher. This avoids the specific error you have come across.

Also, you only ever need import classes once, and it is usually best to do so at the top of your class.

CreITve
02-17-2009, 06:15 PM
Thank you, i've been looking for solution for 2 days)
------
not working...example is for flash, and while trying to paste it in flex got some messages like 'Right bracer required'...i'm new to language I said, sorry if any..:(