Posted by d-train in SWF Studio V3 on Aug 31 2010, 02:47 am

Hi

I use this code...

var return_obj = ssCore.App.showInputBox({prompt:"Please enter your password", title:"Password"});

ssDebug.trace(return_obj.result);


And in the Trace Output window I get null

Am I doing something wrong?

I am using Flash Builder 4 and have just started to code bits to test them before launching into recoding my app.

Thanks

DT


Posted by mbd in SWF Studio V3 on Aug 31 2010, 09:46 am

Welcome!

One of two things is occurring...

Something useful in the SWF Studio API is that you get a notification about whether or not the command succeeded and are provided with an error description.

The Return object always contains a success property, which is a Boolean. If it's ever false you can check the ErrorReturn object on the Return object to see what the problem was. For example:

var return_obj = ssCore.App.showInputBox({prompt:"Please enter your password", title:"Password"});

if (return_obj.success)
{
   ssDebug.trace(return_obj.result);
}
else
{
   ssDebug.trace("ERROR: "+return_obj.Error.description);
}

I'm guessing that the error message will either be about synchronous commands not being enabled, or that the window is not visible.

You can't show a dialog, input, or messagebox* if the window is hidden or not yet visible. If your code is on the first frame, then your app probably just isn't visible yet. You can either wait for it to become visible, or force it with ssCore.Win.show().

* You can also force a messagebox to be visible using the forceShow property on ssCore.App.showMsgBox. Feature added to 3.8.

To enable synchronous commands check out the FAQ in my signature.

We also recommend that if you're going to use a dialog that you use it asynchronously, since the application will be waiting for user input, and is essentially stuck waiting for data to return. If the user takes longer than 15 seconds they might end up with the messagebox from the Flash Player indicating the movie has not responded after 15 seconds.

Here's an example that shows you how to call it asynchronously, while enabling synchronous commands by default. This assumes your code is going in the document class' constructor, or it's on the first frame of the main timeline.

function init(e:Event=null)
{
   ssCore.init();
   ssDefaults.synchronousCommands = true;
   
   ssCore.App.showInputBox({prompt:"Please enter your password", title:"Password"}, {callback:passwordGiven});
}

// The following should be in the main timeline, or the constructor of your Document Class.
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);

function passwordGiven(return_obj:Object, callback_obj:Object, error_obj:Object)
{
   if (return_obj.success)
   {
      ssDebug.trace(return_obj.result);
   }
   else
   {
      ssDebug.trace("ERROR: "+error_obj.description);
   }
}

I recommend you use the bit of code that looks for the stage property being set, because your main SWF is loaded by our API SWF, so the stage property is not set until it's been added to the stage's display list. This is true for any SWF loaded by another SWF - it's not a SWF Studio thing.


Posted by d-train in SWF Studio V3 on Sep 04 2010, 12:42 am

Thanks for the detailed answer, I will look into it over the next week.

Trying to get my head around using an Access Database and reading the data to an array at the moment (with not much luck :()

Thanks again

DT


Posted by northcode in SWF Studio V3 on Sep 04 2010, 02:30 am

Hmmm... This sounds familar. Have we been talking? If so I'm building the example you were looking for. If not, please ignore my ramblings :whacko:


Posted by d-train in SWF Studio V3 on Sep 04 2010, 03:13 am


QUOTE: from northcode;51181
Hmmm... This sounds familar. Have we been talking? If so I'm building the example you were looking for. If not, please ignore my ramblings :whacko:

Hey Tim, yes it's me :)

Had a busy week, so I am hoping to look into it all again this week. The Access database thing is doing my head in :stars:, I'll wait for your email then.

DT


Posted by northcode in SWF Studio V3 on Sep 04 2010, 01:43 pm

The ADO plugin can return data in a delimited format where there are different delimiters between fiellds and rows or it can return the data in XML string format so it can be easilty loaded into an XML object.

I can read a number of rows into a 2-D array or put each row into an array of fields as you read each row but that all requires processing the results that we get back from the plugin. The XML format is actually the easiest to work with IMHO.


Posted by d-train in SWF Studio V3 on Sep 04 2010, 09:31 pm


QUOTE: from northcode;51184
The ADO plugin can return data in a delimited format where there are different delimiters between fiellds and rows or it can return the data in XML string format so it can be easilty loaded into an XML object.

I can read a number of rows into a 2-D array or put each row into an array of fields as you read each row but that all requires processing the results that we get back from the plugin. The XML format is actually the easiest to work with IMHO.


Never used the XML before, so can combo boxes, datagrids, etc use the XML? If that is easier to use, then I am happy to look at the easier alternative :)

DT


Posted by pompeyd in SWF Studio V3 on Sep 07 2010, 09:49 am

Hi DT,

Checkout the DataProvider property for the components you want to use in the FlashBuilder Help - they will tell you what Objects you can use explicitly.

You should/may be able to use the XML Object as the DP by converting the Child Nodes into an XMLListCollection. Or, you may need to cycle through the XMLList (which is basically an ArrayCollection) pulling out the properties of each node as required, and adding them to your own ArrayCollection for use as the DP.

In AS3 the XML Object is a LOT simpler to use than in AS2/1, so it would be worth spending a little time learning the methods used to work with XML.

HTH

Paul


Posted by d-train in SWF Studio V3 on Sep 09 2010, 02:26 am

Thanks Paul - looks like I have a bit of reading to do :twitch:

DT


Posted by d-train in SWF Studio V3 on Sep 12 2010, 02:47 am

Okay, I am slowly getting my head around the XML format, but have a question about what it returns.

I have a location string in the database - EG: c:\database-123\

and what the XML returns is c%3a%5cdatabase%2d123%5c

How can I get it to return the value c:\database-123\ or should (in this case) I grab the data in DLM format instead of XML?

Thanks

DT


Posted by northcode in SWF Studio V3 on Sep 12 2010, 04:40 am

That's the ADO plugin doing that. We have to escape special characters that aren't allowed in XML (the ":" and "\" characters in this case) or Flash would pitch a fit. If you unescape the data yo get back it will make more sense. If you call unescape("c%3a%5cdatabase%2d123%5c") you should get "c:\database-123\" back.


Posted by d-train in SWF Studio V3 on Sep 12 2010, 07:30 am


QUOTE: from northcode;51231
That's the ADO plugin doing that. We have to escape special characters that aren't allowed in XML (the ":" and "\" characters in this case) or Flash would pitch a fit. If you unescape the data yo get back it will make more sense. If you call unescape("c%3a%5cdatabase%2d123%5c") you should get "c:\database-123\" back.

thanks Tim, I had written code to do it, but this is much easier :)

so when I send data to the database c:\database-123\ - will it get saved to the database as c:\database-123\ or c%3a%5cdatabase%2d123%5c?

Not that I care, just wondering that is all.

DT


Posted by northcode in SWF Studio V3 on Sep 12 2010, 11:17 am

The %NN encoding was done strictly to make it possible to represent it as valid XML. If you use the delimited formats you won't see that. Since you're not using XML to send data to the ADO plugin there's no escaping necessary and none performed automatically (like whatever those weird "@" codes were that Zinc made you use). The data is written out exactly as you put it in the insert/update statement.


Posted by d-train in SWF Studio V3 on Sep 12 2010, 05:49 pm


QUOTE: from northcode;51233
The %NN encoding was done strictly to make it possible to represent it as valid XML. If you use the delimited formats you won't see that. Since you're not using XML to send data to the ADO plugin there's no escaping necessary and none performed automatically (like whatever those weird "@" codes were that Zinc made you use). The data is written out exactly as you put it in the insert/update statement.

so the insert, update, etc uses the standard format?

I am using the XML format to grab the data (starting to get my head around it)

If I use the escape() function before I send the text to the database, will it still come back correctly when grabbing the data? I am thinking of when a username may have a hyphen, etc (EG: Tina O'Shannessy).

thanks Tim

DT


Posted by northcode in SWF Studio V3 on Sep 12 2010, 09:46 pm

Anything you pass to ADO.execSQL just has to be a valid string in Flash (so it compiles) and it also has to be valid SQL syntax. So there's two levels there but the rules are pretty simple.

If you use " to define your string in Flash then you have to escape " that appear in that string, but you have complete control over that since you're writing the code. That leaves you free to use ' as the string delimiter in your SQL code. In that case you need to make sure you escape ' characters that appear in the VALUES of your SQL statement.

It might be easier to wrap your head around if you see an example.

The general format of your insert statements will look like this (below). We're going to use " in ActionScript to build the string that contains the SQL that will be passed to the ADO plugin and ' to define string values inside the SQL. So the ONLY thing we have to do is make sure that any occurrence of ' in a value we're using in the VALUES clause is doubled up (escaped). Any other character that's allowable in a Flash string is valid.


var name:String = "Tina O'Shannessy";
name = name.split("'").join("''"); // double up ' chars in SQL values
var age:String = "3";
var sql:String = "insert into [MyTable] (name, age) values ('"+name+"', "+age+")";
trace(sql);


You might want to have a quick peek at my String Literals vs. String Values blog post to brush up on the difference between string values and literals.

It can get a little confusing because we're dealing with two different sets of strings, the outer ActionScript string and the inner SQL syntax with strings of its own.


Posted by d-train in SWF Studio V3 on Sep 15 2010, 02:34 am

Do I need to escape when I do a where statement

They select their login name from a combobox and let's assume that they selected Tina O'Shannessy

var selectedLoginName:String=userCombo.selectedItem;
ssCore.ADO.setSQL({sql:"SELECT DISTINCT UserName FROM Staff WHERE UserName=\'"+selectedLoginName+"\'"});

or do I need to do the

selectedLoginName= selectedLoginName.split("'").join("''");

before I do the SQL call?

EDIT: Answered my own question - yes I do need to do that :)

Thanks


Posted by northcode in SWF Studio V3 on Sep 15 2010, 09:09 am

And I can confirm that for you :)

If you accepted a string from a combobox and assigned it to a Flash var you would not have to escape the string because Flash already put the " or ' into the string properly for you. The only time, in ActionScript, you have to escape strings is when you're building the string in code.

Using the combobox ensures the string is valid for ActionScript, but it may not be valid according to the SQL parsers rules. Because you're dealing with two different systems here (ActionScript and SQL) you will always have to sanitize the inner string (the SQL).


Posted by d-train in SWF Studio V3 on Sep 15 2010, 09:23 am

Thanks Tim

Slowly coming to terms with the SWF Studio way of doing things...got my DataGrid populated, now to add the editing of the cells and update of the database :)

Must say, it is getting easier as I get each breakthrough - just need to think a little differently than before...and in most cases it is easier :)

DT


Posted by northcode in SWF Studio V3 on Sep 15 2010, 09:29 am

It's a bit easier when the product doesn't fight you :evilgrin:


Posted by d-train in SWF Studio V3 on Sep 15 2010, 09:32 am


QUOTE: from northcode;51258
It's a bit easier when the product doesn't fight you :evilgrin:

lol

hey is there a way I can set a column in a dataGrid to have a password mask (i.e. ******** instead of showing the string) and when the user edits the cell it also shows just the ****** not the characters being typed?

will the input box with the password mask be in the next release?

Thanks

DT


Posted by northcode in SWF Studio V3 on Sep 15 2010, 10:12 am

I think you need to use the CellRenderer to change how the DataGrid displays the data in it if you don't like the default rendering.

QUOTE:
will the input box with the password mask be in the next release?Yes, it will.


Posted by d-train in SWF Studio V3 on Sep 17 2010, 11:59 pm

Hi

In Zinc I was able to run a "Compact and Repair" on an Access database - can I do this with SWF Studio and if so how?

Thanks

DT


Posted by northcode in SWF Studio V3 on Sep 18 2010, 03:17 am

It can be done, we just haven't implemented the JRO extension in the ADO plugin because it's specific to Access.

What we'll do is create a new plugin that does just this, since it's actually a pretty useful thing to have around.

There are command line tools that do this if you want to implement something to handle this until we can get a plugin for you. Here's one example I found... http://www.codetoad.com/vb_compact_db.asp


Posted by d-train in SWF Studio V3 on Sep 18 2010, 07:00 am


QUOTE: from northcode;51286
It can be done, we just haven't implemented the JRO extension in the ADO plugin because it's specific to Access.

What we'll do is create a new plugin that does just this, since it's actually a pretty useful thing to have around.

There are command line tools that do this if you want to implement something to handle this until we can get a plugin for you. Here's one example I found... http://www.codetoad.com/vb_compact_db.asp


Thanks Tim, that would be great. Will this likely make it into the next release?

DT


Posted by northcode in SWF Studio V3 on Sep 19 2010, 01:47 pm

I'll put the plugin together and send you a copy (or post it here) so you can try it.


Posted by d-train in SWF Studio V3 on Sep 19 2010, 06:15 pm

Thanks Tim

DT


Posted by northcode in SWF Studio V3 on Sep 20 2010, 10:06 am

Here's the JRO (Jet Replication Objects) plugin that implements the ADO extension to save and compact your MDB files.

All you need to pass is a fully qualified path to the MDB file, the userId and password parameters are optional (if you don't need them, you don't even need pass them, I've just shown them here for completeness).

This will save and compact to a temporary MDB file in the same folder as your source MDB file and when the operation is complete the original will be deleted and the copy will be renamed.

This operation may take some time to complete on a large database, you might want to run this asynchronously to avoid script timeout issues.

In the example here I've used Plugin.loadFromFolder because the plugin won't be installed in the right location. All you have to do to get this example to work is put the JRO.dll in the same folder as your EXE file.

If you copy the DLL to your plugins folder (under the SWF Studio installation folder) then you can just enable it via a checkbox on the plugins tab like any other plugin and you can avoid the loadFromFolder call.


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

ssDebug.trace("starting...");

var r:Object = ssCore.Plugin.loadFromFolder({plugin: 'JRO', alias: 'JRO', path: 'startdir://'});

if (r.success)
{
   ssDebug.trace("plugin loaded");
   var r2:Object = ssCore.JRO.saveAndCompact({path:"c:\\test\\test.mdb", userid:"", password:""});
   ssDebug.trace(r2.success + " [" + r2.Error.description + "] [" + r2.errorText + "]");
}
else
{   
   ssDebug.trace("could not load plugin " + r.Error.description);
}


The implementation was pretty straightforward but I'd backup any MDB file before trying this and please consider this plugin very beta :)

attachments: jro.zip  


Posted by d-train in SWF Studio V3 on Sep 20 2010, 06:04 pm

okay

I added to the pugins directory so my code looks like this...

var r2:Object = ssCore.JRO.saveAndCompact({path:locationDB+"st1.mdb", userid:"", password:myPassword});
ssDebug.trace(r2.success + " [" + r2.Error.description + "] [" + r2.errorText + "]");


My databases are Access 2000 databases and they have a database password setup (no username).

The result is...

false [Operation failed.] [Not a valid password.]

edit:
I assume that this may be a result of the Access 2000 version - in Zinc, one of the things I would pass to it was that it was 2000.

Thanks

DT


Posted by d-train in SWF Studio V3 on Sep 20 2010, 06:14 pm

When it creates the temporary mdb and then deletes the old one, etc - if you are using names without the mdb extension - data.dat for example, will the name remain data.dat or will it be data.mdb?

I have instances where the extension was changed.

DT


Posted by northcode in SWF Studio V3 on Sep 21 2010, 01:16 am

We may need to modify the connection string for older versions of Access, I'll have a look at that.

As long as JRO allows you to use different extensions the app will still work. I just add ".tmp" to whatever you pass in and use that as the temp file. When the operation is done I rename the ".tmp" file to the original input file name.

My example was wrong. The userid parameter should actually be userId but using the wrong case is essentially the same as not supplying a userId argument. That's okay here since you don't need it for your database and it's optional (so you don't need to supply it).


Posted by d-train in SWF Studio V3 on Sep 21 2010, 01:30 am


QUOTE: from northcode;51302
We may need to modify the connection string for older versions of Access, I'll have a look at that.

As long as JRO allows you to use different extensions the app will still work. I just add ".tmp" to whatever you pass in and use that as the temp file. When the operation is done I rename the ".tmp" file to the original input file name.

My example was wrong. The userid parameter should actually be userId but using the wrong case is essentially the same as not supplying a userId argument. That's okay here since you don't need it for your database and it's optional (so you don't need to supply it).


The ADO connection string?

I use

ssCore.ADO.setConnectString({connectString:"Provider=Microsoft.Jet.OLEDB.4.0; Persist Security Info=False; Data Source="+path+"; Jet OLEDB:Database Password="+pass});

and it connects just fine.

DT


Posted by northcode in SWF Studio V3 on Sep 21 2010, 09:44 am

There's a slightly different connection string that has to be used for JRO. Instead of exposing that, I hide it and just ask you for the parameters that I have to stuff in the connection string.

I believe I have to set the Jet engine type so it recognizes the older Access 2000 database. If you were able to compact your database it would have probably upgraded it so that you couldn't open it with Access 2000 anymore.

Can you send a copy of the access database you're using (with the password) to support@northcode.com? I don't need any data in it, I just want to make sure the password stuff works before I get you a new build.


Posted by northcode in SWF Studio V3 on Sep 21 2010, 11:30 am

Here's version 2 of the JRO plugin. This should fix the problem with the password and it automatically determines which version of the Jet engine was used to create the MDB file and compaacts it to the same version, so we don't need to ask you for it.

Can you double check that you can still open the MDB file after compacting?

attachments: jro.v2.zip  


Posted by d-train in SWF Studio V3 on Sep 21 2010, 05:25 pm

Tim

all good now, I can see it opening the files as I see the tmp and then I get the popup showing the info Provider=, Source= and Password=

So all looks good for me.


Posted by northcode in SWF Studio V3 on Sep 21 2010, 11:43 pm

Dang... rookie mistake.
I forgot to remove the message box!
Here's v3 :)

attachments: jro.v3.zip  


Posted by d-train in SWF Studio V3 on Sep 22 2010, 02:58 am

thanks for that Tim, all good


Posted by d-train in SWF Studio V3 on Sep 24 2010, 03:49 am

Okay, there is a strange side effect.

The program still uses the database quite okay, so it appears to be working okay, including the password.

BUT, if I go to open the file in Access after I have run the compact and repair, it opens without asking me for the database password - so for some reason the security is removed. As the data in the database is not for public eyes then this feature will have to remain off until I can use it without the security vanishing.

DT


Posted by northcode in SWF Studio V3 on Sep 24 2010, 09:50 am

That should be an easy fix. Even if compacting the database removes the password, JRO gives us a way to set/change the password so I can always just set the password (to what you pass in) after compacting it.


Posted by Dan in SWF Studio V3 on Sep 24 2010, 02:00 pm

Here's JRO v4.

This version of the plugin maintains the password when performing the compact operation.

attachments: jro.v4.zip  


Posted by d-train in SWF Studio V3 on Sep 24 2010, 05:48 pm

thanks Tim, works fine.

DT


Posted by northcode in SWF Studio V3 on Sep 25 2010, 02:56 pm

Dan made that last change for you, but you're welcome :)


Posted by d-train in SWF Studio V3 on Sep 25 2010, 04:50 pm


QUOTE: from northcode;51351
Dan made that last change for you, but you're welcome :)

Sorry about that Thanks to Dan too :)