Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




XMLSocket.onData And UTF-8 Zero Bytes



I'm currently playing around a bit with Java and Flash's XMLSocket to get them to talk together. The Flash documentation doesn't mention this anywhere, so I assumed that Flash's XMLSocket sends out its data encoded in UTF-8 just like XML.load expects its XML files to be UTF-8 encoded (and won't take anything else even if you tell it to!). This seems to be correct, because I've had Java send the string back as UTF-8 and Flash displayed it fine.

However, there is a slight complication. XMLSocket's EOF marker for both input and output is a single zero byte, but certain high-codepoint Unicode characters get encoded in UTF-8 containing several zero bytes. When I have Java send back a byte sequence containing one of these multi-bytes characters, XMLSocket's onData seems to fire for the zero bytes that are part of the UTF-8 encoded string, as well as the zero byte EOF marker.

Short example: say I have Flash send "abc" over XMLSocket, what it'll actually send is "abc". When encoded as UTF-8, the byte sequence (in hex) for this string is:

Code:
61 62 63 00
My Java server receives this sequence successfully and echoes it back to Flash identically. So Flash then receives:

Code:
61 62 63 00
XMLSocket reads this, fires onData when it hits the last zero byte, and all is fine.

But when I have Flash send a string that contains one or more high-codepoint Unicode characters, say "abc嘹嘻", then it ends up sending "abc嘹嘻". When encoded in UTF-8, the byte sequence (in hex) for this string is:

Code:
61 62 63 E5 98 B9 E5 98 BB 00 00 00 00 00
You can see that the first 3 bytes (61 62 63) are still the same - this is the "abc" part. Now I don't know the exact specifications of UTF-8 encoding, but I do know that for high Unicode code points, UTF-8 will use 1, 2, 3 or 4 bytes, marking each one by flipping on high bits in a unique way so that decoding is possible. So I guess E5 98 B9 is 嘹 and E5 98 BB is 嘻.

There are 5 extra zero bytes at the end, last one of which is the zero byte Flash appended, so I assume each pair of zero bytes is associated with each of these chinese(?) characters. I've noticed the same behaviour with UTF-8 encoded strings with many more high-codepoint characters; they end up with tons of zero bytes at the end. At first I thought Flash might be misencoding this, but my Java testing client encodes to the exact same sequence, so I'm pretty sure it's correct.

So it gets sent to my server, which then echos back the exact same sequence to Flash:


Code:
61 62 63 E5 98 B9 E5 98 BB 00 00 00 00 00
And now, when Flash receives this sequence, it seems to be firing XMLSocket.onData for each of the 5 zero bytes. I can see this happening as I receive it:

ActionScript Code:
xmlSock.onData = function( dat ){trace( "received: " + dat );}

When Flash receives this byte sequence, here's the output I get:

Code:
received: abc嘹嘻
received:
received:
received:
received:
It seems to fire with an empty argument for every additional zero byte. I've tested this and the number always exactly matches the amount of extra zero bytes.

So this forces me to conclude that XMLSocket's onData method is, well, stupid. It should first try to parse a UTF-8 string by capping off the last zero byte rather than bluntly going through the received bytes front to back and firing onData on every zero bytes it encounters. But then again, the first output it gives me is "received: abc嘹嘻", which is in fact the correct UTF-8-decoded string. So why does it go over the extra zero bytes (again?) that were part of the UTF-8 string ?

Now the "fix" for this is easy: add

ActionScript Code:
if( dat == null || dat == "" ) return;
in my onData method. This works, but I don't consider it a fix.

Any information on this ? Is XMLSocket.onData really as stupid as I think it is, or is it me being stupid ? If it's set to interpret received data as UTF-8, how can it possibly do this correctly if onData bluntly fires for every zero bytes that crosses its path without considering the possibility that it's part of a UTF-8 string ?



ActionScript.org Forums > ActionScript Forums Group > ActionScript 1.0 (and below)
Posted on: 08-07-2007, 01:16 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

XMLSocket.onData And UTF-8 Zero Bytes
I'm currently playing around a bit with Java and Flash's XMLSocket to get them to talk together. The Flash documentation doesn't mention this anywhere, so I assumed that Flash's XMLSocket sends out its data encoded in UTF-8 just like XML.load expects its XML files to be UTF-8 encoded (and won't take anything else even if you tell it to!). This seems to be correct, because I've had Java send the string back as UTF-8 and Flash displayed it fine.

However, there is a slight complication. XMLSocket's EOF marker for both input and output is a single zero byte, but certain high-codepoint Unicode characters get encoded in UTF-8 containing several zero bytes. When I have Java send back a byte sequence containing one of these multi-bytes characters, XMLSocket's onData seems to fire for the zero bytes that are part of the UTF-8 encoded string, as well as the zero byte EOF marker.

Short example: say I have Flash send "abc" over XMLSocket, what it'll actually send is "abc". When encoded as UTF-8, the byte sequence (in hex) for this string is:

Code:
61 62 63 00
My Java server receives this sequence successfully and echoes it back to Flash identically. So Flash then receives:

Code:
61 62 63 00
XMLSocket reads this, fires onData when it hits the last zero byte, and all is fine.

But when I have Flash send a string that contains one or more high-codepoint Unicode characters, say "abc嘹嘻", then it ends up sending "abc嘹嘻". When encoded in UTF-8, the byte sequence (in hex) for this string is:

Code:
61 62 63 E5 98 B9 E5 98 BB 00 00 00 00 00
You can see that the first 3 bytes (61 62 63) are still the same - this is the "abc" part. Now I don't know the exact specifications of UTF-8 encoding, but I do know that for high Unicode code points, UTF-8 will use 1, 2, 3 or 4 bytes, marking each one by flipping on high bits in a unique way so that decoding is possible. So I guess E5 98 B9 is 嘹 and E5 98 BB is 嘻.

There are 5 extra zero bytes at the end, last one of which is the zero byte Flash appended, so I assume each pair of zero bytes is associated with each of these chinese(?) characters. I've noticed the same behaviour with UTF-8 encoded strings with many more high-codepoint characters; they end up with tons of zero bytes at the end. At first I thought Flash might be misencoding this, but my Java testing client encodes to the exact same sequence, so I'm pretty sure it's correct.

So it gets sent to my server, which then echos back the exact same sequence to Flash:


Code:
61 62 63 E5 98 B9 E5 98 BB 00 00 00 00 00
And now, when Flash receives this sequence, it seems to be firing XMLSocket.onData for each of the 5 zero bytes. I can see this happening as I receive it:


ActionScript Code:
xmlSock.onData = function( dat ){trace( "received: " + dat );}


When Flash receives this byte sequence, here's the output I get:

Code:
received: abc嘹嘻
received:
received:
received:
received:
It seems to fire with an empty argument for every additional zero byte. I've tested this and the number always exactly matches the amount of extra zero bytes.

So this forces me to conclude that XMLSocket's onData method is, well, stupid. It should first try to parse a UTF-8 string by capping off the last zero byte rather than bluntly going through the received bytes front to back and firing onData on every zero bytes it encounters. But then again, the first output it gives me is "received: abc嘹嘻", which is in fact the correct UTF-8-decoded string. So why does it go over the extra zero bytes (again?) that were part of the UTF-8 string ?

Now the "fix" for this is easy: add

ActionScript Code:
if( dat == null || dat == "" ) return;
in my onData method. This works, but I don't consider it a fix.

Any information on this ? Is XMLSocket.onData really as stupid as I think it is, or is it me being stupid ? If it's set to interpret received data as UTF-8, how can it possibly do this correctly if onData bluntly fires for every zero bytes that crosses its path without considering the possibility that it's part of a UTF-8 string ?

XmlSocket / OnData
Like many others before me, I am having problems with the xmlSocket object and specifically with the onData event not firing.

Object defined thus:


Code:
myXML = new XMLSocket;
myXML.onConnect = handleConnect;
myXML.onClose = handleDisconnect;
myXML.onData = handleData;
myXML.connect("localhost", 9090);

function handleData() {
trace("data");
}
(I left out the other functions but they are defined).

My socket server is set up to send back a simple welcome message when a client connects. Using Telnet I can connect and get the welcome message back. In Flash I connect and nothing... or at least onData doesn't fire.

Checking the log my server generates tells me it is sending the message to Flash.

I've read the past posts on this subject and it seems everyone says something along the lines of "the string needs to be terminated by a null byte" and in my server (written in PHP) I've tried "", chr(0) and nothing (assuming that if PHP uses a null byte to end a string anyway I don't need to add one) and Flash still doesn't seem to respond to the incoming data.

Am I missing something obvious? Can anyone help at all?

thanks.

Overriding XMLSocket.onData
Hi everyone,

The Actionscript docs say it's possible to override XMLSocket.onData to intercept the XML text without parsing it.

http://www.macromedia.com/support/fl...ionary865.html

I've tried my best but I really can't figure it out!!

Any help would really be appreciated.

I'm currently developing a Flash Client that recieved plain text in the form of LoadVars style data.

XMLSocket OnData Issue
I am trying to narrow down a bug in an application that utilizes the XMLSocket class. I have reduced it to the following code below. Is there such a scenario that practically simultaneous messages sent from a server would cause 'false' to be traced more than once (ie. can the code in the onData method evaluate test as false more than once because onData is called a second time before the first onData method has had time to update test to true)? Can the onData method be treated as atomic? To a certain degree....?

At the root of this question, I am trying to grasp how asynchronous calls are handled/queued to make sure I understand them correctly and prevent certain cases where a single-time operation may occur twice. If any one can help or direct me to information regarding this, I would be very thankful.

Dan







Attach Code

var test:Boolean = false;
XMLSocket.prototype.onData = function (src) {
if(!test) {
trace('false');
test = true;
}
else {
trace('true');
}
}

XMLsocket OnData Problems
I can't seem to figure this out. I've read about the scoping problems. I've seen senocular's tutorial even. However, I can't seem to figure out what's wrong with this implementation.
*Note: I don't use XML, so I prototyped the onData to get rid of the XML parsing part.

If you could help me fix this I would be very grateful. I've been looking at it and testing it for like two days now.

Code:
class NetworkingManager {

public var mySocket:XMLSocket;
function NetworkingManager() {
//variable to access this while inside an event
var nmObj:NetworkingManager = this;
this.mySocket = new XMLSocket();
this.mySocket.connect("localhost", 3333);

this.mySocket.onConnect = function(success) {
if (success) {
trace("Server connection established!");
} else {
trace("Server connection failed!");
}
nmObj.printData("HERE IN THE ON CONNECT")
};

this.mySocket.onClose = function() {
trace("Server connection lost");
};

this.mySocket.prototype.onData = function(msg:String):Void {
trace("DATA"+msg);
nmObj.printData(msg);
};

}
public function Ping():Void {
mySocket.send("ping");
}
public function printData(msg:String):Void {
trace("DATA: "+msg);
}
}

XMLSocket.onData Receiving Bad Data
I have a movie that uses the XMLSocket object to receive and process character strings from a simple VB app which is connected to a serial device. The purpose of the system is to synchronize events detected by the serial device with corresponding movies on the display. We've had this system up and running in the field for a little over a year now with no reported issues.

I recently copied the working code into a second movie intended for a similar use and discovered a strange phenomenon. I am still receiving the correct string argument when onData is called, but now it's appended onto a variable number of 9s. For example:

Expected : "5,0,0,0,00012500"
Received : "999999995,0,0,0,00012500"

Luckily, the first character of the string is, by design, always a single digit number, so all I had to do was a quick mod 10 after the split to get rid of the garbage, but I'd still like to know just what might be going on here.

I'm still using the same VB app to mediate with the serial port, and it still functions perfectly with the other movie so I'm inclined to rule out problems in that code. One point of possible interest is that the second movie wouldn't connect to the server at all until I went back and published it for Flash 7 instead of Flash 8; The first movie was published for 7 and it was the only difference I could find between the two.

If anyone has any suggestions as to where or how I should look into this problem, please share. I honestly have no idea how to proceed.

XMLsocket.prototype.onData Not Triggering
I am trying to connect to a device which supports sending status updates using a simple TCP connection. However, I can't get the onData event to trigger. I am trying to connect to 192.168.200.100, and it shows it successfully established the connection, but it isn't showing the data.

When I telnet to this device, I can see the data. The only thing I can think of is that the data isn't terminated with a null character, but I am hoping this really isn't the issue, as this would be a big show stopper.


Code:
mySocket = new XMLSocket();

mySocket.onConnect = function(success)
{
if (success)
msgArea.htmlText += "<b>Server connection established!</b>"
else
msgArea.htmlText += "<b>Server connection failed!</b>"
}

mySocket.onClose = function()
{
msgArea.htmlText += "<b>Server connection lost</b>"
}

mySocket.prototype.onData = function(msg)
{
trace("onData triggered")
trace("MSG: " + msg)
msgArea.htmlText += msg
}

mySocket.connect("192.168.200.100", 10000)

XmlSocket OnData From Inside A Class
Hi,

I have a class which opens an XMLSocket. I would like my onData function to access other functions in my class. The trace calls work, but calling my own private functions does not.

Here's the code


Code:
class Megastream(){
private var socket:XMLSocket;
private var port:Number = 9999;
private var host = "localhost";


public function MegaStream(){
this.createSocket();
}

private function createSocket():Void {
this.socket = new XMLSocket();
this.socket.connect(host, port);
this.socket.onConnect = function(success) {
trace("Connection Status: " + success);
if(success) {
trace ("connected java server");
}else{
trace ("something is wrong");
}
}
this.socket.onClose = function() {
trace("Connection To Server is Closed");
}
this.socket.onData = function(data:String) {
trace("Getting Data: " + data);
this.printData(data);
}
}
private function printData(data:String):Void{
trace("printData : " + data);
}
}
So, when I instantiate an object, I get this output when my server sends data:

Quote:




Connection Status: true
connected java server
Getting Data: imfromjava




But then there's no "PrintData : imfromjava." It seems any private functions I call from onData will not work. It won't show an error either. Any ideas?

Thanks!
rusew

Why Doesnt My OnData XMLSocket Work
I cant get any data - what am i doing wrong?

I try this:

socket = new XMLSocket();
function myonData(data) {
indata.text = data;
}
Socket.onData = myonData;

indata.text is a dynamical text-area

It works with a connect and it also works with sending data to the server.

can somebody help?

Get Bytes Loaded And Bytes Total When Loading A JPG From A Different Domain
im probably better posting this here...

I have a online photo album but im likely to run out of server space for my images so i load pictures from different servers.

When ever i load in an image i have a progress bar that shows the bytes loaded and bytes total properties of that image.

Now if i load in an image that exists on the same server as the photo album swf then my progress bar works fine and it gets the bytes loaded and bytes total of that image, but if i load an image that is on a different server than the album then it doesnt get the bytes loaded or total, even though the image does load.

Is this part of macromedias security issues, what are macromedias security issues on this topic?

Any ideas round this?

I also found that the onData event for a movie clip doesnt work when your loading an image from a different server, but it does if you load an image from the same server as the swf. I got round this by checking if the height of the MC where the image was loading had changed, if it had then the image had loaded in.

cheers

Get Bytes Loaded And Bytes Total When Loading A JP
I have a online photo album but im likely to run out of server space for my images so i load pictures from different servers.

When ever i load in an image i have a progress bar that shows the bytes loaded and bytes total properties of that image.

Now if i load in an image that exists on the same server as the photo album swf then my progress bar works fine and it gets the bytes loaded and bytes total of that image, but if i load an image that is on a different server than the album then it doesnt get the bytes loaded or total, even though the image does load.

Is this part of macromedias security issues, what are macromedias security issues on this topic?

Any ideas round this?

I also found that the onData event for a movie clip doesnt work when your loading an image from a different server, but it does if you load an image from the same server as the swf. I got round this by checking if the height of the MC where the image was loading had changed, if it had then the image had loaded in.

cheers

OnData Help
Hey guys,

I need some help ... I find out a way to get a text file in without using variables ...

example

bCode,bItemName,bDescription,bPics,bPrice
SM,Small Box,16"x12"x12",smallBox.jpg,$1.99
MED,Medium Box,18"x18"x16",mediumBox.jpg,$2.99

this is how I get the data in

code:
var _lv = new LoadVars();

_lv.onData = function(dat) {
var input_arr = dat.split('
');
if (input_arr.length==1) {
input_arr = dat.split('
');
}
for (i=1; i<input_arr.length; i++) {
trace(input_arr[i].split(','));
}
};
_lv.load("testFile2.txt");


he is the issue ...

I'm never going to know how many rows there is going to be at any givin time ...

so what I'm asking is ... I need a way to split each row (once in flash) in its own array ... so that I can take out different indexes ...

I tried using a for loop to it didn't work ...

I'm guessing I need to know how to make dynamic arrays ...

please someone help

thanks

-S

OnData ? For Jpg's
Hi,
I am loading jpg's, and I want to make a Movieclip('MC') invisible when there is no jpg to load (because it just is not there). How can I detect if there is no jpg, and then make the MC invisible? I think I should use onData, but I can't make it work.


Code:
function laadNail3(foto) {
var my_lv:LoadVars = new LoadVars();
my_lv.onData = function(src:String) {
if (src == undefined) {
MC._visible = false;
}
foto = src;
};
my_lv.load(foto, holder);
}

I am also confused where to put the Movieclip that holds the jpg ('holder')?

The data passed to the function comes from another swf, saying:

Code:
laadNail3("b3.jpg");


Could someone show me how to do this?

thank you,

Jerryj.

OnData?
Hey!

is there a way to do something if there's any content loading into your main movie? something like:


Code:
_root.onData = function(){
trace('data is loading');
}

Hope someone knows it

OnData Jpg
Hi,
I am loading jpg's, and I want to make a Movieclip('MC') invisible when there is no jpg to load (because it just is not there). How can I detect if there is no jpg, and then make the MC invisible? I think I should use onData, but I can't make it work.

ActionScript Code:
function laadNail3(foto) {    var my_lv:LoadVars = new LoadVars();    my_lv.onData = function(src:String) {        if (src == undefined) {            MC._visible = false;        }        foto = src;    };    my_lv.load(foto, holder);}

I am also confused where to put the Movieclip that holds the jpg ('holder')?

The data passed to the function comes from another swf, saying:
laadNail3("b3.jpg");[/as][as]

Could someone show me how to do this?

thank you,

Jerryj.

OnData
I have been piecing some code together to try to get this working and am still having some problems, I can get the connection to establish but I cannot get the onData function to work. If anyone has any insight to this it would be greatly appreciated!

function lsOnConnect(success) {
if (success) {
trace ("Connection succeeded!")
} else {
trace ("Connection failed!")
}
}


var socket = new XMLSocket();
socket.onConnect = lsOnConnect
if (!socket.connect('ipnumber', 0000)) {
trace ("Connection failed!")
}


socket.onData = function(success){
if (success){
trace ("loaded");
}
else {
trace("XML did not load");
}
}

OnData?
Hey!

is there a way to do something if there's any content loading into your main movie? something like:


Code:
_root.onData = function(){
trace('data is loading');
}

Hope someone knows it

OnData (?)
am i doing something wrong here or can i not use onData with loadMovie?


Code:

createEmptyMovieClip("target", 1);
target._x = target._y = 100;
target.onData = function () {
trace("movie has been loaded");
};
target.loadMovie("theimage.jpg");

OnData Not Being Called?
myMovieClip.onData = function(){
trace("on data called");
}

myMovieClip.loadMovie("picture.jpg");




why is it not calling onData?

OnData Not Working ?
Hi,

I built the site http://www.jps-foto.de/jps.htm, were a photographer shows his pictures. There are categories with thumbnails, each thumb an individual jpg being loaded by loadMovies. onData should check if they are complete.

On my system it works fine. On other systems (especially slow connections or Macs) sometimes there seem to be are problems. Switching too fast between the categories causes some kind of overload, even the transmission should stop.

At http://www.jps-foto.de/Saupe11test4.swf there is a test showing the player version and some variables at loading.

Does anybody have an idea? I checked the programming carefully, but there was some discussion about old players not loading correctly which should be working now.
It would be a great help to have information on what systems/players this doesn't work.

Mc.onData Problem...
I've tried, on numerous occasions, to use loadMovie with mc.onData = function() {} in MX. However, I can never seem to get it to work. According to the documentation, I can use onData with loadMovie commands to determine when the entire movie has finished loading. Unless my syntax is all screwed up, this doesn't seem to work.

here's a sample

loadMovie("movie.swf","clipName");

clipName.onData = function() {
trace("movie loading done");
}

This always fails...any thoughts?

Cheers

Quasi

OnLoad/onData
Tring to write a dynamic image display for any dimension jpg file.
Code i have written is as follows.

var depth=0
var i=0

createEmptyMovieClip("ImageHolder",depth)


this.onMouseDown=function()
{
loadImage()
}

function loadImage()
{
i++
Mov="Images/Image"+i+".jpg"

ImageHolder.loadMovie(Mov)
ImageHolder.onLoad=checkSize();
}


function checkSize ()
{
trace(ImageHolder._width)
//resize code to go here
ImageHolder._x=0
ImageHolder._y=0

}

loadImage()


this loads OK but the onLoad Event is triggered immediately rather than after Loading of the Image. As i want to change th properties of the ImageHolder Movieclip depending on its new dimensions this is causing a bit of a problem.


Has anyone had any problems with the .onLoad event and solved it, or can see any mistakes i am making.

Any help appreciated

OnData Event Help
thank you first for reading this
i got a little problem about MovieClip.onData event handler
I've check the event invoked when a movie clip receives data from a loadVariables or loadMovie call.
but the problem is
---------------------------
_root.createEmptyMovieClip("testMc",0);
testMc.onData = function(){
trace(this._width);
}
testMc.loadMovie("test.jpg");
------------------------------
didnt work! it only works when AS in onClipEvent(data)

can anyone tell me how to let it invoke?
or onData Event handler only works by use loadVariables?

Has Anybody Got OnData Working?
I've been braking my head for a good while now, trying to use the Movieclip.onData handler. It's supposed to be a listener, right? Why doesn't the following trace a thing??:


Code:
placeholder.onData = function () {
trace ("there's data");
}
loadMovie(temp, placeholder);


My objective, of course, isn't just tracing, but first things first. I've tried a number of other alternatives (always with onData), and none have worked out... anybody's ever gotten this event to work? Can anyone provide an example of code where it does work?

Thanks, everyone!

OnData Trouble
stop();
mc.onData = function() {
if (mc.getBytesLoaded() >= mc.getBytesTotal()) {
play();
}
};
mc.loadMovie(String(newpage)+".swf");

I am using this code to load a new page into a movie clip and check to see that it is entirely load befor playing, the reason i posted this is becuase it doesn't wor. please help

OnData Question
if i create a function using onData, does this occur when the data starts loading, or after it is completed? Testing locally, i am unable to tell the order of operation.

-myk

OnData Problem
I expect the onData function to be called when the jpg is completely loaded but it is not..What am I doing wrong!
Thanks!

this.Back_mc.prototype.loadImage = function()
{
this.createEmptyMovieClip( "instEmpty_mc", 2 );
this.instEmpty_mc.loadMovie( "trio.jpg" )

}

this.instEmpty_mc.onData = function()
{
this.instEmpty_mc._x = 160;
this.instEmpty_mc._y = -220;
this.instEmpty_mc._xscale = 5;
this.instEmpty_mc._yscale = 5;
}

MyMovieClip.onData
For what can be used this method?


Code:
myMovieClip.onData = function () {
trace ("onData called");
};
Thanks Jan

OnData Function?
I am loading external jpgs and swf files in my movie. I am trying to call a function when the external content loads. Right now I am using this code:


Code:
onClipEvent (data) {
//play closing transition
_root.closeTrans();
}
Here is the problem; the on data is unreliable. Sometimes it calls the function twice, or too early. What else can I do to call the action when the data finishes loading?

Using MovieClip.onData
Can you tell mi for which functioncan i use it please?

Any simple example?

Flash 5 And OnData
can any 1 explain me for which o when do i use the
MC.onData event, and if some 1 have an example code its great too!
on flash 5!!!
thnaks i nadvance
peleg

OnData Or OnLoad?
Hi there!

Since some time ago, I have developed a lot of Flash projects with database integration (even in PHP as will in ASP).

Though, there is something that bugs me... onData and onLoad events used in LoadVars. As you already know, the basic method to access an external script is:


PHP Code:



DataSender = new LoadVars();
DataReceiver = new LoadVars();
// put here the function to receive data sent back
DataSender.sendAndLoad ("scriptname",DataReceiver,"POST");




However you need to get ready to receive the data sent back to Flash (as commented above), by the script. Well, normally, I do that by using onLoad event, this way:


PHP Code:



DataReceiver.onLoad = function()
{ trace (dataReceiver);}




Ok, it works like a clock. However, it the server fails, sometimes Flash keep trying and waiting forever.

Then, I found out that using onData event, you can prevent server timeout, this way:


PHP Code:



DataReceiver.onData = function(src)
{
if (src == undefined)
{ trace ("server failed"); }
else
{ trace ("ok"); }
}




The problem is that, if you use onLoad you cannot prevent server failure. However if you use onData, you CAN prevent server failure but DataReceiver will not be loaded with content sent back to Flash for the script.

Anyone there know how to deal with that?

Synchronous OnData
I'm building a quiz in flash. After each question is answered, I send the result to the database to record the answer and return a count of what others have answered for each answer. Something like this:


Quote:




var target_xml:XML = new XML();

target_xml.onData = function(src:String) {
if (src == undefined){ version.text = "Error getting results";
} else {
var src_xml:XML = new XML();
src_xml.ignoreWhite = true;
src_xml.parseXML(src);
var aryTemp:Array = new Array;
for (var a:XMLNode = src_xml.firstChild.childNodes[2].childNodes[0], j=0; a!=null; a=a.nextSibling,j++) {
aryTemp.push(a.childNodes[1].childNodes[0].toString());
}
resultsArray.push(aryTemp);
totalArray.push(src_xml.firstChild.childNodes[1].childNodes[0].toString());
if (qPosition == qCount) {
qPosition = 0;
nextFrame();
};
}; //end success boolean
};
resultsXML.sendAndLoad("http://www.quizical.net/histories", target_xml);




The resultsArray stores the selected count of each answer. The totalArray stores a count of how many times the question has been answered. So in a quiz that has 5 questions, my resultsArray.length would be 5 and my totalArray.length would be 5. When I'm presenting the results of each question, I use a position counter to access the right total count from totalArray, like totalArray[questionNumber].

The problem is that occassionally the results of one question are loaded and parsed faster than the previous one and its results get placed in the count arrays before the previous one. Basically the results get out of order sometimes.

My question is how can I ensure that the next question is not processed before the current question is processed? I tried using onLoad instead of onData since onLoad seems to also include parsing rather than just receiving the data. This piece happens in the background while the student is taken the quiz.

OnData Problem
Dear list, I have a class which opens an XMLSocket. I would like my onData function to access other functions in my class, but it is not working. I attached an approximation of my code.

So, when I instantiate an object, I get this output when my server sends data:

Connection Status: true
connected java server
Getting Data: imfromjava

But then there's no "PrintData : imfromjava." It seems anything I call from onData will not work. It won't show an error either. Any ideas?

Thanks!
Rob









Attach Code

class Megastream(){
private var socket:XMLSocket;
private var port:Number = 9999;
private var host = "localhost";


public function MegaStream(){
this.createSocket();
}

private function createSocket():Void {
this.socket = new XMLSocket();
this.socket.connect(host, port);
this.socket.onConnect = function(success) {
trace("Connection Status: " + success);
if(success) {
trace ("connected java server");
}else{
trace ("something is wrong");
}
}
this.socket.onClose = function() {
trace("Connection To Server is Closed");
}
this.socket.onData = function(data:String) {
trace("Getting Data: " + data);
this.printData(data);
}
}
private function printData(data:String):Void{
trace("printData : " + data);
}
}

Datagrid - OnData Or Something?
Hi All,

I need my script to somehow detect when the data in a datagrid has been updated [not by the user, like on(Change) but like onData or something]

Is there anything that can detect this?

Using MovieClip.onData
Can you tell mi for which functioncan i use it please?

Any simple examle?

OnData && #include
Alright, I know that onData is used to send the raw contents of a text file to a text field...but can it be used along the lines of #include?

I have a .txt file with contents:


Code:

some_var = 1;
some_other_var = 2;
and now when I load those variables using:

ActionScript Code:
loadText = new LoadVars();loadText.load("vars.txt");loadText.onData = function(src){//some function using src}

If I use: trace(src) in the onData function, I see the variables like I want them to be. How do I get those variables to be set as if they were written in the actual flash actionscript? I know how to do it with text string manipulations...but that isn't an option for this.

Thanks for any help.

Datagrid - OnData Or Something?
Hi All,

I need my script to somehow detect when the data in a datagrid has been updated [not by the user, like on(Change) but like onData or something]

Is there anything that can detect this?

Using MovieClip.onData
Can you tell mi for which functioncan i use it please?

Any simple examle?

SendAndLoad And OnData
A couple of silly xml questions:

1. If i override XML.onData event, do I have to some how call the function?
example here a sample override

XML.prototype.onData = function (src) {
  if (src == undefined) {
    this.onLoad(false);
    //more stuff
    //more stuff
  } else {
    this.parseXML(src);
    this.loaded = true;
    this.onLoad(true);
    //more stuff
  }
}


do I have to later call onData like this
XML.onData(parameter);



2. If my file exists locally on my computer, can I use XML.sendAndLoad where the url is a full url to a site? or is that a security issue and I can only sendAndLoad locally on the file system? Currently I am getting an error opening a url. I have access to that url but testing locally on my pc. Do i have to be on the file system for this to work?

thanks

Success OnData? & Z-value Of Mc's
Last edited by Codemonkey : 2006-04-21 at 05:13.
























hi everybody!
well, i got this code... and i'd like to personalize it more... 'cause it shows a message only if .css file fails... what about the .htm file, how can i do it?
it could be better if someone knows the way the make a link in the "load failed message" to load again those files... or just refresh de page...


ActionScript Code:
// Create a new style sheet and LoadVars object
var myVars:LoadVars = new LoadVars();
var styles = new TextField.StyleSheet();
// Location of CSS and text files to load
var txt_url = "news.htm";
var css_url = "news.css";
// Load text to display and define onLoad handler
myVars.load(txt_url);
myVars.onData = function(content) {
storyText = content;
};
// Load CSS file and define onLoad handler:
styles.load(css_url);
styles.onLoad = function(ok) {
if (ok) {
// If the style sheet loaded without error,
// then assign it to the text object,
// and assign the HTML text to the text field.
svnews.styleSheet = styles;
svnews.text = storyText;
} else {
svnews.htmlText = "<br><br><br><br><br><br><br><br><p align='center'><font color='#FF0000'>¡ERROR!<BR>CARGA DE DATOS FALLIDA</font></p>";
}
}

hope u can help me, it doesn't seem difficult

and... there is some code to make a movie clip stay over the other elements? like above in layers? 'cause i load a swf in other swf... and i need a mc stay over the elements in the main swf

thanx ni advance
cheers!

(yes, my engish isn't good )

LoadVars + OnData + If
there is some as

ActionScript Code:
String.prototype.rmCR = function() {
   return this.split("\r").join("");}
logowanie = function (l, h) {
   a = new LoadVars();
   a.login = l;
   a.haslo = h;
   a.sendAndLoad("login.php", a, "POST");
   a.onData = function(rawstring) {
      if (rawstring == undefined) {
         _root.gotoAndStop("blad");
      } else if (input=rawstring.rmCR()) {
         tr = rawstring;
         _root.gotoAndStop("strefa");
      } else {
         input = tr = rawstring;
         _root.gotoAndStop("blad");
      }
   };
};

"input" and "tr" shows variables in dynamicText fields - value always is "true" but the second condition (else if) always returns false - why??

OnData Function
Is there a way of activating the onData event without having to attach the code to the MC.

Currently I have a MC on the stage called Img and Im loading in an external .jpg file. I want to scale it when its loaded so I have added this code to it.


ActionScript Code:
onClipEvent(Data){
Scale Code Here
}


What I want to do is remove this code from the MC and put it on the time line instead. I tried this but its not working for some reason.


ActionScript Code:
Img.onData = function(){
Scale Code Here
}


The code inside the function never seems to be called even though the image has been successfully loaded although it does work in the first example above.

Yet Another OnData Problem
this is what the dictionary says


Description


Event handler; invoked when a movie clip receives data from a loadVariables or loadMovie call.


now. granted, thats pretty vague, but my interpretation would be..whenever the flash player gets the totalBytes of the movie or jpg to load, this would trigger. UH ......NO!. seems this is only triggering once THE ENTIRE JPG IS LOADED.
thats the same as onLoad, is it not??

or maybe its just me....

heres the scenario:

have a folder with images to be presented dynamically.
image names are 0.jpg 1.jpg 2.jpg 3.jpg etc.. up to 10.jpg
i have a function to check if the file is there starting at "10.jpg" and going backwards.


Code:
checkFolder(10);
function checkFolder(myIndex){
Images = new LoadVars();
folderName = _root.globalFolderName;
Images.load(_global.useURL + "inventory/" + folderName + "/" + myIndex + ".jpg");
Images.onData = function(){
if(Images.getBytesTotal() > 0){
trace("checking folder contents resulted in: " + Images.getBytesTotal() + " totalBytes, With " + Images.getBytesLoaded() + " Bytesloaded");
play();
_global.imagesInFolder = myIndex;
_root.imageNav_mc.gotoAndPlay("in");
_root.imageNav_mc.isPlaying = true;
_global.loadNumber = 0;
}else{
myIndex --;
checkFolder(myIndex);
}
}
}
so if 10.jpg isnt in the folder then when onData triggers, Images.getBytesTotal() will = "" and so forth.
NOW: once it finds a jpg and onData triggers, Images.getBytesTotal() and Images.getBytesLoaded(); are the same thing, usually around 100k.

in other words THE WHOLE FREAKING FILE LOADED BEFORE onData TRIGGERED!!!
WHY? OH GOD WHY?
please help

OnClipEvent (data) Vs OnData
every time I try to use a method instead of a function, I get funny results!

I have an external txt: 1.txt wich has only one variable in it: texto=something
and a mc called ball on the stage

if I put this code in the first frame:

_root.bola.onLoad = function() {
this.loadVariables("1.txt");
};
_root.bola.onLoad();
_root.bola.onData = function() {
trace(texto);
};

I get undefined, which means that onLoad has been triggered but why do I get undefined?


if I put this in the bola:

onClipEvent (load) {
this.loadVariables("1.txt");
}
onClipEvent (data) {
trace(texto);
}

I get the expected result: something

what's the theory behind this?

OnData And OnLoad Question
Hi,

I have read a few threads on onLoad and onData. It seems like onLoad and onData doesn't work when I load a swf file into an empty movieclip.
eg
_root.content.loadMovie("MenuNav/ProductNav.swf");
_root.content.onData= function () {
trace("onload called");
};

Other threads have mentioned some work arounds, eg zaxis mentioned a file called movieclipfix.mxp but the link is no longer active. Can someone please help?

Thanks in advance.

Joe

LoadMovie And OnData Trouble
I've been working for some hours (grr) with loading an external 64kb swf into a movie.
On my home computer this works fine, but when I publish the files (yes, they're in the same folders, and they are the correct filenames etc, etc, and I have put the plug in the wall...), the external swf doesn't get loaded.
I've also tried to use an onData-check, to halt the movie until the huge file's loaded.
Nothing happens, the onData's never called.
Here are the codes I've been using now:
Code:
filmstrip_mc.loadMovie("filmstrip.swf",10);

filmstrip_mc.onData = function () {
trace ("onData called");
};
I've also tried
Code:
loadMovie("filmstrip.swf","filmstrip_mc");

filmstrip_mc.onData = function () {
trace ("onData called");
};
Please help me, somebody. I'm tearing my hair out...()

Mc.onData() Vs OnClipEvent(data)
hello,
Can anyone clarify the differenct between using movieclip.onData and onClipEvent(data)?
I have a movie in which this is on the first frame:
code:
loadMovie("somestuff.swf",_root.socket);


_root.socket.onData = function()
{
trace("loaded some stuff");
}


there is a container clip called "socket".
In this previous example nothing happens when the clip is loaded.
But if i put an onClipEvent(data) handler on socket:
code:
onClipEvent (data) {
trace("data recieved");
}

it works fine.
According to the macromedia reference it should do exactly the same thing. Anyone know why, and how to make the mc.onData() function work??
cheers!

Movieclip.onData = Problem
hello!

I'm having problems detecting when a movie has loaded into a socket movie clip using movieclip.onData = function();

Basically, i'm loading "new.swf" from the main movie in to a movieclip on the _root timeline. This movieclip is called "socket".

.. so ther's a button with this on it:
code:
on(release)
{
loadMovie("new.swf", "_root.socket");
}

and there's this in on a keyframe the _root timeline:
code:
_root.socket.onData = function()
{
trace("finished loading movie");
}

My understanding is that it should load the movie into 'socket' and then, when it's finished, perform the trace action. But it doesn't!

Anyone know what i'm doing wrong?

Also, to add to my confusion, it *does* work if i trigger the trace action from onClipEvent(data) on the actual 'socket' clip.

Thanks for any help!
pog

Copyright © 2005-08 www.BigResource.com, All rights reserved