2 Replies Latest reply on Oct 31, 2007 1:28 AM by mplebani

    Modules and SharedObject

    mplebani
      Hi all,
      I use sharedObject not only as Flex-cookie, but also as a sharing container for my application.
      In my last work (I am currently using Flex 3 beta) I noticed the shared object is not so shared as declared. In particular, I have an application in which there are a canvas and a moduleLoader; if the canvas writes a variable into the SharedObject "X", the module loaded by ModuleLoader is not able to read this information. It seems that there are two different working space for the two component. Below, you can find an sample application that demonstrate my Application. There is a way to solve that problem, or this is a wanted feature of Flex?

      ============================================================
      APPLICATION

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">
      <mx:Panel x="10" y="10" width="250" height="200" layout="absolute">
      <mx:Button id="scriviA" x="10" y="10" label="Scrivi" width="70" click="{funcscriviA()}"/>
      <mx:Button id="leggiA" x="10" y="40" label="Leggi" width="70" click="{funcleggiA()}"/>
      <mx:TextInput id="textA" x="88" y="10" width="132"/>
      <mx:Label id="labelA" x="88" y="42" text="Label"/>
      </mx:Panel>
      <mx:Panel x="268" y="10" width="250" height="200" layout="absolute">
      <mx:Button id="scriviB" x="10" y="10" label="Scrivi" width="70" click="{funcscriviB()}"/>
      <mx:Button id="leggiB" x="10" y="40" label="Leggi" width="70" click="{funcleggiB()}"/>
      <mx:TextInput id="textB" x="88" y="10" width="132"/>
      <mx:Label id="labelB" x="88" y="42" text="Label"/>
      </mx:Panel>

      <mx:ModuleLoader url="ModuleCanvas.swf" x="10" y="218"/>
      <mx:Script>
      <![CDATA[
      private function funcscriviA():void{
      var shared:SharedObject = SharedObject.getLocal("pippo");
      shared.data.pippo = textA.text;
      shared.flush();
      }
      private function funcleggiA():void{
      var shared:SharedObject = SharedObject.getLocal("pippo");
      labelA.text = shared.data.pippo;
      }
      private function funcscriviB():void{
      var shared:SharedObject = SharedObject.getLocal("pippo");
      shared.data.pippo = textB.text;
      shared.flush();
      }
      private function funcleggiB():void{
      var shared:SharedObject = SharedObject.getLocal("pippo");
      labelB.text = shared.data.pippo;
      }
      ]]>
      </mx:Script>
      </mx:Application>

      ============================================================
      Module

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Module xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="266" height="220">

      <mx:Panel x="10" y="10" width="250" height="200" layout="absolute">
      <mx:Button id="scriviA" x="10" y="10" label="Scrivi" width="70" click="{funcscriviA()}"/>
      <mx:Button id="leggiA" x="10" y="40" label="Leggi" width="70" click="{funcleggiA()}"/>
      <mx:TextInput id="textA" x="88" y="10" width="132"/>
      <mx:Label id="labelA" x="88" y="42" text="Label"/>
      </mx:Panel>

      <mx:Script>
      <![CDATA[

      private function funcscriviA():void{
      var shared:SharedObject = SharedObject.getLocal("pippo");
      shared.data.pippo = textA.text;
      shared.flush();
      }

      private function funcleggiA():void{
      var shared:SharedObject = SharedObject.getLocal("pippo");
      labelA.text = shared.data.pippo;
      }


      ]]>
      </mx:Script>
      </mx:Module>

      ============================================================

      Thanks!