Posted by pbena in SWF Studio V3 on Apr 24 2008, 05:39 am

Sorry for my english .... I'm french

I want to make only one file (a standalone created with swfstudio v3) ... and I want the users can change some text variables in the exe and I want these changes enregistred in the .exe.

My swf have several dynamic text box (named var1, var2, ...ect) that the users can write to update the text ... and when the users re-launch the .exe, all variables must stay updated.

I try your example "Write data to your EXE and read it back [33]" but it seems works only for one variable (?)

I need your help to do this if it is possible ... thanks by advance


Posted by mbd in SWF Studio V3 on Apr 24 2008, 10:33 am

You can only write text to the scratch area. If you want to combine multiple values you'll need to encode them to write them, and then decode them when reading them. An easy way to do this is to use the LoadVars object, since it does this for you.

For example, the following code will store some variables a LoadVars object and then write that to the scratch area. Afterwards, it reads the data and then uses another LoadVars object to decode the data.

ssCore.init();
ssDefaults.synchronousCommands = true;

function writeData()
{
   var r;
   var lv;
   
   lv = new LoadVars();
   lv.var1 = 'value 1';
   lv.var2 = 'value 2';
   lv.var3 = 'value 3';

   r = ssCore.Scratch.write({data:lv.toString()});

   if (r.success)
   {
      ssDebug.trace('Data written successfully as: '+lv.toString());
   }
   else
   {
      ssDebug.trace('ERROR writing data:'+r.Error.description);
      ssDebug.trace(' Data is: '+lv.toString());
   }
}

function readData()
{
   var r;
   var lv;
   
   lv = new LoadVars();

   r = ssCore.Scratch.read();

   if (r.success)
   {
      lv.decode(r.result);

      ssDebug.trace('Data read successfully');
      ssDebug.trace('var1 = '+lv.var1);
      ssDebug.trace('var2 = '+lv.var2);
      ssDebug.trace('var3 = '+lv.var3);
   }
   else
   {
      ssDebug.trace('ERROR reading data:'+r.Error.description);
   }
}

Call writeData() and then readData().


Posted by pbena in SWF Studio V3 on Apr 24 2008, 11:54 am

thanks for your response ... but I am a newbie and I think I missed something :

I make a simple swf (flash cs3) with only one image. On this image I put 3 text areas that I call var1, var2 and var3 ... and I put this action-image :


ssCore.init();
ssDefaults.synchronousCommands = true;
function writeData()
{
   var r;
   var lv;
   
   lv = new LoadVars();
   lv.var1 = 'value 1';
   lv.var2 = 'value 2';
   lv.var3 = 'value 3';
   r = ssCore.Scratch.write({data:lv.toString()});
   if (r.success)
   {
      ssDebug.trace('Data written successfully as: '+lv.toString());
      }
      else
      {
         ssDebug.trace('ERROR writing data:'+r.Error.description);
         ssDebug.trace(' Data is: '+lv.toString());
      }
   }
   
function readData()
{
   var r;
   var lv;
   lv = new LoadVars();
   r = ssCore.Scratch.read();
   if (r.success)
   {
      lv.decode(r.result);
      ssDebug.trace('Data read successfully');
      ssDebug.trace('var1 = '+lv.var1);
      ssDebug.trace('var2 = '+lv.var2);
      ssDebug.trace('var3 = '+lv.var3);
      }
      else
      {
         ssDebug.trace('ERROR reading data:'+r.Error.description);
      }
   }
   


Then I make an .exe with this swf on swfstudio3.3.
I launch the .exe, I write something in the three areas .. I close the .exe ... and when I re-launch the .exe, the three areas are "blank" ???
What I've missed ?

Thanks for your help !


Posted by mbd in SWF Studio V3 on Apr 24 2008, 12:53 pm

Are you publishing for ActionScript 1/2 or 3? I was assuming ActionScript 1 or 2. If it's 3 you'll get a number of errors, since the LoadVars object doesn't exist and you need to include the V3 component in your library. If you're not using ActionScript 3 then don't worry about any of that.

Are you calling writeData() or readData() at any point? The code I posted by itself won't do anything until you call one of those functions.

Place a button on stage that calls writeData().

In the main timeline, just below the code I gave you call readData(). The data will be written when you press the button and should be read when your EXE starts up again.

Also, make sure you enable the debug option in the Output tab before you build your EXE. Then have SWF Studio open to the Trace tab before you launch the EXE so that ssDebug.trace message will appear there.


Posted by pbena in SWF Studio V3 on Apr 24 2008, 02:29 pm

I'm publishing in actionscript 2 ...
I place a button with this action code
on (release) {
   writeData();
   }

Just after the code you gime me I put this line code :

readData();

I enable the debug option in the Output tab.
Just after "build", the .exe launch and in the trace output there is :
Data read successfully
var1=undefined
var2=undefined
var3=undefined


I write on the .exe, "hello world1" in the first text box (var1) and "hello world2" in the second text box (var2) and "hello world3" in the third text box (var3) ... and I click on the button ..
In the trace output there is :
Data read successfully
var1=undefined
var2=undefined
var3=undefined
Data written successfully as : var3=value%203&var2=value%202&var1=value%201


I close the .exe and re-launch it.
The 3 text areas are " blank" and in the trace output there is :
Data read successfully
var1=undefined
var2=undefined
var3=undefined
Data written successfully as : var3=value%203&var2=value%202&var1=value%201
Data read successfully
var1=value1
var2=value2
var3=value3


Where is the problem ... I remember you, i'm a newbie ... perhaps I've missed an evident thing ?
Thanks for your help !


Posted by mbd in SWF Studio V3 on Apr 24 2008, 02:45 pm

So, by the trace output it's working. The issue is an understanding of what I've done with the variables. You can't just name a textfield var1 and have the code work. I just wanted to show you how to assign a value to a LoadVars object that you could use to store the data.

Instead of writing "value 1" to lv.var1, write the text from the textfield using the text property: TextField.text. If you've called the textfield "var1", then it would be var1.text.

And instead of displaying lv.var1 in the Trace tab write the value to the textfield, again using the text property: var1.text = lv.var1.

If you're having some issues with textfields, variables, and objects I would suggest picking up a good ActionScript book for AS1 and AS2, and/or take a look at some tutorials.


Posted by pbena in SWF Studio V3 on Apr 24 2008, 04:01 pm

:) I progress ... I progress ...

The new actionscript code in the first image :

ssCore.init();
ssDefaults.synchronousCommands = true;
function writeData()
{
   var r;
   var lv;
   
   lv = new LoadVars();
   lv.var1 = var1.text;
   lv.var2 = var2.text;
   lv.var3 = var3.text;
   r = ssCore.Scratch.write({data:lv.toString()});
   if (r.success)
   {
      ssDebug.trace('Data written successfully as: '+lv.toString());
      }
      else
      {
         ssDebug.trace('ERROR writing data:'+r.Error.description);
         ssDebug.trace(' Data is: '+lv.toString());
      }
   }
   
function readData()
{
   var r;
   var lv;
   lv = new LoadVars();
   r = ssCore.Scratch.read();
   if (r.success)
   {
      lv.decode(r.result);
      ssDebug.trace('Data read successfully');
      ssDebug.trace('var1 = '+lv.var1);
      ssDebug.trace('var2 = '+lv.var2);
      ssDebug.trace('var3 = '+lv.var3);
      }
      else
      {
         ssDebug.trace('ERROR reading data:'+r.Error.description);
      }
   }
   
readData();


and in the trace output, after I launch the .exe and write in the text areas and re-launch the .exe :
Data read successfully
var1=undefined
var2=undefined
var3=undefined
Data written successfully as : var3=hello%20world%203&var2=hello%20world%202&var1=hello%20world%201
Data read successfully
var1=hello world 1
var2=hello world 2
var3=hello world 3


... but the 3 text areas are blank on the .exe ... grrrrr !
Pleaaaaase .... give me the good code .. or perhaps what I want to do is not possible ? Pleaaaaase ...


Posted by mbd in SWF Studio V3 on Apr 24 2008, 04:22 pm

It is definitely possible. I explained how to do it in my previous post, although you may have missed part of it.

You did the right thing in writeData: the LoadVars variables are being assigned with the textfield text. However, in the readData function you didn't change anything so the values are only being traced out, they aren't being written to the textfields. You have to write the code to assign the value to the textfield:

QUOTE:
And instead of displaying lv.var1 in the Trace tab write the value to the textfield, again using the text property: var1.text = lv.var1.


Posted by pbena in SWF Studio V3 on Apr 24 2008, 04:53 pm

It's works !!! you are great !
Many many thanks ...


Posted by pbena in SWF Studio V3 on Apr 24 2008, 05:14 pm

.. but I've not finish ( sorry ).
In fact, this .exe is destined for a professor and his students. Only the professor must be able to upate the variables, so these variables must be have two instances : one in dynamic text areas (for the students) and an other in a private part (acces with password) on text areas can be written by the professor to update them.
So I have two questions :
1/how to attribute an initial value to var1, var2, var3 ?
2/ how can have 3 dynamic text areas in an other part of the swf who have the same value that my 3 variables (var1, var2, var3) ?

Thanks ... but you are not obliged to help me this time ...


Posted by pbena in SWF Studio V3 on Apr 25 2008, 05:34 pm

I've find all the solutions of my questions ... thanks for your help !