Solved

loadVars.send in Projector

Posted on 2003-11-21
20
641 Views
Last Modified: 2008-01-09
Greetings,

In a flash projector exe file I am using loadVars.send() method to send data to my own server (Developed using Java Socket programming).
Below is my action script code:

myLoadVars = new LoadVars()
myLoadVars.somevar = "someval"
myLoadVars.send("http://10.10.11.35:1500/forflash.txt","","GET");

Everything works fine, but when sending data it is opening new browser window which i doesn't want.

Is is possible to disable the window parameter of send method.

Hope you all getting my question.

Thanks for your time.

Vivek

0
Comment
Question by:mvkvivek
  • 9
  • 6
  • 4
  • +1
20 Comments
 
LVL 9

Expert Comment

by:OBCT
Comment Utility
try this:
myLoadVars.sendAndLoad("http://10.10.11.35:1500/forflash.txt","","POST");

Cheers

-OBCT
0
 

Author Comment

by:mvkvivek
Comment Utility
Hi,

Thanks for the response.

I tried both the following:

myLoadVars.sendAndLoad("http://10.10.11.35:1500/forflash.txt","","POST");
myLoadVars.send("http://10.10.11.35:1500/forflash.txt","","POST");

It is not sending any response to server and new Window is not opening.

Simple words Nothing happens if I used both the above.

Thanks
0
 
LVL 9

Expert Comment

by:OBCT
Comment Utility
I'm not sure if you've tried this or if it will even work but it's worth a shot.

myLoadVars = new LoadVars();
myLoadVars.somevar = "someval";
loadVariablesNum("http://10.10.11.35:1500/forflash.txt","0","GET");
or
myLoadVars = new LoadVars();
myLoadVars.somevar = "someval";
loadVariablesNum("http://10.10.11.35:1500/forflash.txt","0","POST");

Cheers

-OBCT
0
 

Author Comment

by:mvkvivek
Comment Utility
Thanks agin OBCT!

But I am not trying to load a txt file, I am trying to send data from a flash (Projector) movie to my own HTTP server.

I can able to send data using send method, but the player is opening the browser window.

How can avoid this.

Thanks

Vivek
0
 
LVL 9

Expert Comment

by:OBCT
Comment Utility
Sorry for not reading your question properly, I have become well known for doing that.
Give me about an hour and I'll see what I can find on fixing your problem.

Cheers

-OBCT
0
 
LVL 9

Expert Comment

by:OBCT
Comment Utility
Have you tried using this:

myLoadVars = new LoadVars()
myLoadVars.somevar = "someval"
myLoadVars.send("http://10.10.11.35:1500/forflash.txt","0","GET");

The only difference is that I've put a "0" in the window string, this means that everything is being sent to your server, but once I had the same problem and when I used the zero, the window stopped popping up.
I just hope that it fixes your problem.

Cheers

-OBCT
0
 

Author Comment

by:mvkvivek
Comment Utility
Oops....

I tried this and this also popping up.  :o(

Can you upload it for me. Also tell me what server you are using to test this.

Expecting your reply.

Thanks
0
 
LVL 9

Expert Comment

by:OBCT
Comment Utility
Unfortunatly the server I use crashed and I lost everything so I'm not testing any of this, I'm just passing information from previous encounters of the same problem.
So just to be safe.....if you use the GET method, the data is sucessfully sent to your server but the window pops up, and if you use the POST method, the data is not sent and the window does not pop up.

To be perfectly honest, I don't understand why it is having this problem.
I am currently working on an online game. In the exe file we have the registration form and we use loadVariablesNum to send our data the the database and no window pops up.
Just a few questions...
What is in the window that pops up? Is it blank?
Have you tried this:

myLoadVars = new LoadVars()
myLoadVars.somevar = "someval"
myLoadVars.send("http://10.10.11.35:1500/forflash.txt", ,"GET");  //Now there is no target specified.

I just read an article on macromedia.com on the send function and I think the problem is that flash thinks that "" is a target window, therefore opening up IE.
If it doesn't work, we'll keep trying.

Cheers

-OBCT
0
 
LVL 9

Expert Comment

by:OBCT
Comment Utility
0
 

Author Comment

by:mvkvivek
Comment Utility
Hi

I have read this article.

Also I tried using
myLoadVars.send("http://10.10.11.35:1500/forflash.txt", ,"GET");  //Now there is no target specified.

Now also windows pops up.

But what you said is perfectly right:

if we use the GET method, the data is sucessfully sent to your server but the window pops up, and if you use the POST method, the data is not sent and the window does not pop up.

Just to add with that.

Both happens only we didn'g give any of four (_blank, _top, _self, _parent) windows property.

I don't know how to over come this...

FYI: If we use loadVariablesNum the window won't pop-up.
Answer for your question:
In the new window it is trying to load the specifed url.

http://10.10.11.35:1500/forflash5.txt?onLoad=%5Btype%20Function%5D&somevar=someval //For Post method
http://10.10.11.35:1500/forflash5.txt?somevar=someval //For Get method.

Hope I'll get some solution for this.

Thanks





0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Expert Comment

by:Rouneh
Comment Utility
Hi,

Have you considered using the XMLSocket function instead of LoadVars? (If you're coding the Java Socket server yourself it should not pose a problem)

var serverSocket;
function setupSocket() {
   serverSocket = new XMLSocket();
   serverSocket.onData = function() {
     // Do stuff with whatever data the server sends to you
   }
   serverSocket.connect("yourServerHostNameOrIP", portWhereServerIsListening);
   // Note that this socket will be connected until you disconnect it either from the server or through the serverSocket.disconnect() function.
}
function sendSocket(data) {
   // data = any string message
   serverSocket.send(data + '\0');
   // The \0 character is what flash regards as end of message
}

I assume you know what to do with the data from the server side?

Regards,
Rouneh.
0
 
LVL 27

Expert Comment

by:negatyve
Comment Utility
1. The standalone flash player for windows *always* uses the "GET" method, even if you have specified "POST" (this is a bug)
2. The send method is similar to the movieclip getURL method, so the popop page coming is normal

3 A possible solution is to use sendAndLoad method instead, and have the server send back a response to the calling application

(ie, the server, once received data, send back this string to flash "&received=OK&")

myLoadVars = new LoadVars();
myLoadVars.somevar = "someval";
myLoadVars.onLoad = function(success)
{
      if(success){
            if(this.received == "OK")trace("YEAH!!");
      } else {
            trace("SERVER NOT FOUND");
      }
};
myLoadVars.sendAndLoad("http://10.10.11.35:1500/forflash.txt", myLoadVars, "POST");
0
 

Author Comment

by:mvkvivek
Comment Utility
Thank you experts.

I used sendAndLoad and it works fine. I was wondering why other not working while this is working. Thanks negatyve for your explanation.

Still I have some problems with my own httpServer. Hope i'll solve it and implement this. I'll come back to this once I solved the server problem

Thanks for your time OBCT.

0
 

Author Comment

by:mvkvivek
Comment Utility
I am back again.

Now the loadVars.sendAndLoad is working fine in both PC & Mac.

I tried using XML.sendAndLoad and this is working fine in PC but not in Mac.

Flash Player is sending the information to Server and the server is also responding back but the Flash player never makes the success of onload function to true.

Is this is a bug?

Is anybody tried this over mac?

Thanks in advance
0
 
LVL 27

Accepted Solution

by:
negatyve earned 125 total points
Comment Utility
Try overwriting the onData event handler:

data_xml.onData = function (rawData)
{
      if (rawData == undefined) {
            this.onLoad(false);
      } else {
            this.parseXML(rawData);
            this.loaded = true;
            this.onLoad(true);
      }
};
data_xml.onLoad = function(success)
{
      if (success) {
            // use your new loaded xml data
      } else {
            trace("XML FILE NOT FOUND");
      }
};
0
 

Author Comment

by:mvkvivek
Comment Utility
Great,

It is working fine now.

Possible Can you explain me why we need to overwrite onData?

Thanks for the solution.
0
 
LVL 27

Expert Comment

by:negatyve
Comment Utility
>Possible Can you explain me why we need to overwrite onData?

it's kind of a known bug on mac. i cannot tell you where i have red it - it's that inner knowledge you do not where it comes from [but it's there] :)
0
 
LVL 27

Expert Comment

by:negatyve
Comment Utility
beside that. the "loading complete" event for xml and loadvars is onData, which by default calls the onLoad event handler. so, before onload is fired, everything go through "onData" (which is rarelly overwritten). the loadvars one is:

data_var.onData = function (rawData)
{
    if (rawData == undefined) {
         this.onLoad(false);
    } else {
         this.decode(rawData); // decode instead of parseXML - decode is undocumented
         this.loaded = true;
         this.onLoad(true);
    }
};
data_var.onLoad = function(success)
{
    if (success) {
         // use your new loaded data
    } else {
         trace("FILE NOT FOUND");
    }
};
0
 

Author Comment

by:mvkvivek
Comment Utility
Hi,

I still have some problem with the sendAndLoad.

Let me explain my problem.

I have one textfield and two buttons as movieclip in the main time line. Following is the is code which is placed in first frame of the movie.

loadVars_mc.caption_txt.text = "LoadVars";
XML_mc.caption_txt.text = "XML";

myLoadVars = new LoadVars()
myLoadVars.somevar = "someval"

xmlStr = "<tag>value</tag>";
myXML = new XML(xmlStr);


loadVars_mc.onRelease = function() {
      myLoadVars.sendAndLoad("http://10.10.11.35:1500/",myLoadVars,"POST");
}

XML_mc.onRelease = function() {
      myXML.sendAndLoad("http://10.10.11.35:1500/",myXML,"POST");
}

myLoadVars.onLoad = function(success) {
      if (success) {
            trace(this);
      }
}

myXML.onLoad = function(success) {
      trace("on load");
      if (success) {
            trace(this);
            _root.somevar = this;
      }
}

myXML.onData = function (rawData)
{
             trace("inside onData");
     if (rawData == undefined) {
          this.onLoad(false);
     } else {
          this.parseXML(rawData);
          this.loaded = true;
          this.onLoad(true);
     }
}

Both these buttons used to send data (loadvars & XML) to the server. It is working fine in Authoring environment, but it is not sending any data to server in .exe.

Any guess why it is?.....

Many thanks
Vivek
0
 

Author Comment

by:mvkvivek
Comment Utility
Anybody is reading this....?
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now