Posted by absolom in SWF Studio V3 on Sep 18 2008, 07:08 am

Hi.

I have on many places in my flash/northcode application, strange behaviour.
I have to click twice to make things working right.

For a little example, here what I am trying to do :

I get the language of my aplication, using XML and PHP.

Here are the functions :


function getLangue()
{
   this.anticache = new Date().getTime(); 
   langueXML=new XML();
      langueXML.onLoad=function(){
         _root.langue = langueXML.childNodes[0].childNodes[0].childNodes[0].nodeValue;
      };
      langueXML.ignoreWhite=true;
      langueXML.load(_root.remoteURL+"createXmlGetLangue.php?anticache="+this.anticache);
}

function SupportFaq ()
{
   _root.getLangue();
   
   if(_root.colone._currentframe==1)
      _root.colone.gotoAndPlay(2);
      _root.menuIndex.b1.gotoAndStop(1);
      _root.menuIndex.b3.gotoAndStop(1);
      _root.menuIndex.b4.gotoAndStop(1);
      _root.menuIndex.b6.gotoAndStop(1);
   
   if(page=="" || page==undefined)
      page="index.php";
   ssCore.Browser.showScrollbars({flag:true}); 
   ssCore.Browser.setPosition({x:-18, y:-5});      
   ssCore.Browser.setSize({width:1052, height:650});
   ssCore.Browser.setURL({url:"http://faq1.esthetic-center.com?langue="+_root.langue});
   ssCore.Browser.open();
   _root.embedWindow=1;
}


The Php code is the one :


header("Expires: Fri, Jun 12 1981 08:20:00 GMT");
header("Pragma: no-cache");
header("Cache-Control: no-cache");

include("../Classe/absolom.class.php");
require_once("../config.inc.php");
$noEta = $DB->queryFirst("SELECT langueEtablissement from etablissement");
$retour='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
                      <absolom>
                          <version>'.strtoupper($noEta).'</version>
                      </absolom>';
echo utf8_encode($retour);


In my FLASH application, when i first click on the FAQ button, I don't have the right language, but if I click again, it's ok.

Then, I try to change the language, I click on FAQ, this is this the old language...

Any idea ???

Thanks a lot...


Posted by northcode in SWF Studio V3 on Sep 18 2008, 10:20 am

This FAQ http://www.northcode.com/v3/kbitem.php?link=6 explains the most likely cause of why you have to double click.


Posted by mbd in SWF Studio V3 on Sep 18 2008, 10:22 am

The getLangue function does not receive data from XML immediately. It sets up the XML object and makes the call. At some point (when the computer contacts the server and the server eventually sends the data back to the computer where Flash receives it) your XML.onLoad function will be called. When you click the second time it works because the data was received from the first call and you then use that data.

This is a basic function of Flash - XML, as well as other external communication objects, are asynchronous. That means you setup a function that will receive data, then make a call. The call goes out and your animations and ActionScript continue along. When data is received your receiving function is called.

Hopefully that was clear. Take a look at some Flash tutorials on XML, LoadVars, etc.


Posted by absolom in SWF Studio V3 on Sep 18 2008, 10:34 am

Thanks for the help...

As you can see, I am not an expert of FLASH, but I have to maintain a whole POS application based on FLash/Studio, and we have no choice, no one know Flash very well.

That's why I am asking your help, I know weel the Php language, and I have add some new features since 1 year, but we have so much strange beahaviour with our software...

Our Flash developper is not part of the company now, and when I look into the code, it's all big shit, with lots of uncomprehensive name for the methods and the variable...

Anyway, could you please just explain me how I should rewrite the call of data from Php, in order that it is excuted and immediatly ready for the appliction ?

I could, if you want, send you the code.

Thanks,

Absolom.


Posted by mbd in SWF Studio V3 on Sep 18 2008, 10:48 am

Instead of calling SupportFaq first, call getLangue first. Inside of the langueXML.onLoad function call SupportFaq. You'll probably have to target SupportFaq, though. The easiest way, although not the best way, is to do something like this:
langueXML.parent = this;
langueXML.onLoad = function ()
{
_root.langue = langueXML.childNodes[0].childNodes[0].childNodes[0].nodeValue;
this.parent.SupportFaq();
}

Make sure to take out the call to getLangue inside of SupportFaq.


Posted by absolom in SWF Studio V3 on Sep 18 2008, 11:27 am

What is strange to me, is that id i make a view of langueXML.childNodes[0].childNodes[0].childNodes[0].nodeValue;, it always return the right value, but when accessing the _root.langue, it's not good...


Posted by mbd in SWF Studio V3 on Sep 18 2008, 11:46 am

It's when you're accessing it. Inside the onLoad function it will look fine.

You have to understand the sequence of events. This is what happens with your code:

1. SupportFaq is called.
2. You call getLangue.
3. langueXML is created.
4. langueXML.onLoad is defined.
5. langueXML.load is called.
6. The rest of the code in SupportFaq runs, including trying to use _root.langue.
7. langueXML.onLoad is called and _root.langue is assigned a value.

Then if you run the process again _root.langue is already populated by the time you get back to step 6, since it was set in step 7 of the previous run.

You will have to change your project to call getLangue, and then wait for the langueXML.onLoad to be called before trying to access _root.langue. That's the way it has to be done.


Posted by absolom in SWF Studio V3 on Sep 18 2008, 12:19 pm

Thanks, it's now well clear right now.

But how can I force the fonction to WAIT for the onLoad to finish the action ???

Thant's what I am trying to do, but without success...

I tried this :


langueXML=new XML();
      langueXML.onLoad=function(success){
         if (success) {
            _root.langue = langueXML.childNodes[0].childNodes[0].childNodes[0].nodeValue;
         }
      };
      langueXML.ignoreWhite=true;
      langueXML.load(_root.remoteURL+"createXmlGetLangue.php?anticache="+this.anticache);


That's not better...

I should make a synchronus call, am I right ?


Posted by mbd in SWF Studio V3 on Sep 18 2008, 12:37 pm

You can't force XML.load/onLoad to be synchronous for remote files. Don't think in those terms.

Either call your XML load at startup so it's ready for anything else that uses the data, or change the way you access the data. If the data will not change during the course of your application, then just get the data at startup. If it does change, then you'll have to change your code to setup a function that is called when the data is returned, then ask for the data. When the data is returned the rest of your functionality can continue.

This is beyond the scope of SWF Studio - I can help point you in the right direction but you need to learn some Flash or hire someone to help you with your project.


Posted by absolom in SWF Studio V3 on Sep 18 2008, 12:47 pm

OK, thanks you for all...
I will try to learn, but I don't have too much time for it, this is not my goal usually...

And thanks for your good application.