re-requesting xml data after updating variables in Flash - mysql

Having a few problems that after three days of googling and coding I am unable to find any suitable answers so, I'm hoping that someone with far more Flash AS3 knowledge than me can help. I have frame on the Maintimeline of a flash Movie which requests and loads PHP generated XML. The PHP file is passed three variables from Flash which are then used to populate certain parts of the MySQL query in the PHP file. It all works wonderfully and I can populate a myriad dynamic text fields via my loadXML function. here's my code:
var req:URLRequest=new URLRequest("http://example.com/returnusers.php");
req.method = URLRequestMethod.POST;
var phpVars:URLVariables = new URLVariables();
phpVars.Group = myVar1;
phpVars.Company = myVar2;
phpVars.startRow = myStartRow;
req.data = phpVars;
var xml:XMLList;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, loadXML);
xmlLoader.load(req);
My problem is that I also have several buttons that, when clicked, will change the values of the myVar1, myVar2 and myStartRow. and thus change the parameters of the query in the PHP file. I would like to resend these to the same PHP file for an updated xml output and for my dynamic text fields to be updated with the new xml data.The only problem is is that I don't know how. As you can problably tell I'm no Tech Wizz but I'd really appreciate if someone out there could help... Thanks in advance

What you are trying to implement is a classic MVC design - in simple words you have a model (database + php) that is dynamic (changes during run time) and you want your view to change according to the changes made in the model (the view is binded to the model)
The solution requires some architectural work that is a bit advanced and will take some learning time , this is a good start : http://www.moock.org/lectures/mvc/

Related

Get mime/type from MediaPromise

I am trying to make my scrips as cross-platform as possible. I am using CameraUI to fetch files and upload them to Firebase. The problem is I can only get the bytearray through the filepromise and not the file extension..or anything. According to numerous guides iOS wont let you get mediaPromise.file to get it's type. So I'm left with the question of how to get a mime/type from this bytearray I have, that I know is either an image or a video from MediaPromise.type.
MetaData or anything would help.
Following this guide gets me to a security error. Something with domains. I'm in Android and iOS so I can't do Security.allowDomain("*"); I made my own version by following this guide.
I searched and found this guide, and this works. But it only fetches the bytearray..
He wrote another article that made something that extracted data from the first 64K of the bytearray or something and displayed it in his app. He used a lib that's no longer up so I can't really go with his guide.
The code in there is the code I have in my script aside from a few UI management additions. How would I go about solving this? Is there some meta-data that always lies in the first set of bytes?
I even tried using this nice ANE, but I get an error..
You can get the mime type once the mediapromise was loaded:
cameraUI = new CameraUI();
if (CameraUI.isSupported)
{
cameraUI.addEventListener(MediaEvent.COMPLETE, onCameraUIComplete);
cameraUI.addEventListener(Event.CANCEL, onCameraUICanceled);
cameraUI.addEventListener(ErrorEvent.ERROR, onCameraError);
cameraUI.launch(MediaType.IMAGE);
}
private function onCameraUIComplete(e:MediaEvent):void
{
var mediaPromise:MediaPromise = e.data;
if (mediaPromise)
{
myLoader = new Loader();
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onMediaPromiseLoaded);
myLoader.addEventListener(IOErrorEvent.IO_ERROR, onMediaPromiseLoadError);
myLoader.loadFilePromise(mediaPromise);
}
}
private function onMediaPromiseLoaded(e:Event):void
{
var myLoaderInfo:LoaderInfo = e.target as LoaderInfo;
var myByteArray:ByteArray = myLoaderInfo.bytes;
var mimeType:String = myLoaderInfo.contentType;
}
Another way is to determine the mimetype "manually" based on the file extension in mediaPromise.file.extension

Load data via GET from URL in Flash / AS3

I know it's 2016 and this is a question about Flash...
Sadly a lot of the Flash AS3 resources are no longer available as the format has fallen out of favour with web devs and the tutorials I have managed to find are all done on earlier versions of Flash - I have CS6, and some of the functions/commands don't seem to work the same way.
So my question for you S.O gurus...
How do I load any kind of data into a swf movie via a GET URL.
For example :
www.example.com/mymovie.swf?loadfile=myfile.mp3
I know I can do the following to load an external file :
var url:String = "http://example.com/myfile.mp3";
var soundFile:URLRequest = new URLRequest(url);
But instead of hard coding the url how do I tell it to look for the data in the loadfile variable delivered via the incoming request?
The answer in case anybody else stumbles across this :
loaderInfo.parameters['loadfile']
Gets the variable from the url

how to load and edit a sql database from adobe flex builder 4.6 air program

Alright I have my sqldb hosted online and can access it using phpmyadmin what i would like to do is create tables and add items to the tables via adobe flex builder 4.6 desktop AIR application.
Anyone know if i am able to do this, the idea for the program is so person at position A can enter a name and person at position B can then use his program to read those names
According to Accessing mysql from Adobe flex/AIR, AIR is unable to access MySQL servers directly, so you'll have to use web services or some custom API do to this. But yeah, sure it's possible to do what you want.
I agree with Isaac. However, I want to add that it is good coding practices to not allow client side applications modify a database directly. In the applications that I have built, I like to use PHP to set-up an API that then interacts with the database. The AIR application then the interaction with the API using HTTP Requests.
Following code shows how to perform a URL request from the Adobe Website.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html
var url:String = url location of the API;
var request:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables(); //create variables to pass to the API
variables.exampleSessionId = new Date().getTime(); //create variables to pass to the API
variables.exampleUserLabel = "guest"; //create variables to pass to the API
request.data = variables; //Add the variables to the request
request.method = URLRequestMethod.POST; //Set the method of the Request GET, POST, PUT
navigateToURL(request); //Executes the request
You'd probably like something like https://backendless.com/ for this.

Is there any best way to implement Encryption in Flex 3

we have one application where we are pulling some confidential information from one of the product design tools. So we have used HTTPS as the channel and also we are encrypting the Request Parameters and Some data before we sent it to Web Services. So, Everything seems OK.
But when we gave the application for Security auditing they found we have hard coded the encryption key in source code. They have used Sothink SWF Decompiler to look into my SWF file. They caught the key and raised concern over it.
We have developed this application using Flex 3(SDK 3.4). Is there any best way to use Secret key without being hard coded in source code. If anybody come across this kind of problem, please let me know.
Anyone, please suggest me the best way to use the secret keys in SourceCode without being Hard coded.
Here is my sample code:
var currentResult:String = "";
var strDataToEncrypt:String = "";
var kdata:ByteArray;
var todayDate:Date = new Date();
kdata = Hex.toArray(Hex.fromString("secretKey here"));
strDataToEncrypt =username.toUpperCase() + "#$#" + password + "#$#" + todayDate.getTime().toString();
var data:ByteArray;
data = Hex.toArray(Hex.fromString(strDataToEncrypt))
var name:String = "des3-ecb";
var pad:IPad = new PKCS5;
var mode:ICipher = Crypto.getCipher(name, kdata, pad);
pad.setBlockSize(mode.getBlockSize());
mode.encrypt(data);
currentResult = Base64.encodeByteArray(data);
var token:String = currentResult;
There is no such thing as complete protection with Flash. Your keys have to be either in the code or loaded externally, and at some point anyone who is determined enough will be able to get them. All you can do is make this process so complex that it's not worth the hassle.
Have a look at this question for ways to make your source harder to decompile and read: How to protect swf file from being decompiled?
don't send your data as url parameters. send it with a post request.
if that's not possible you could try implementing a scheme with a public key. but be careful, chances are high that you implement something wrong which leads to even bigger security problems.

What would cause Flash (AS3) to substitute in & for & in GET query params?

I've spent a day on this so far and just can't figure it out. The problem is that Flash is apparently substituting & for & in my GET query params.
So for example, I'm sending into a URLLoader a URLRequest with a url similar to this:
http://foo.blah.com/app/index.php?abc=def&ghi=jkl&mno=pqr
I verified this by looking at the var in the debugger. Yet it's failing on our server. Ethereal reports that what is actually going over the wire is this:
GET /app/index.php?abc=def&ghi=jkl&mno=pqr
Not the first, but the second & is being replaced with &.
I can't figure out how to make it stop doing this. What could cause this? Or does anyone have any ideas of things I can investigate?
Use the data property to construct the passed GET variables (you will have to set the request method to GET as well, check out the AS3 documentation for more granular information).
example :
var getVars:URLVariables = new URLVariables();
getVars.abc = "def";
getVars.ghi = "jkl";
var request:URLRequest = new URLRequest();
request.data = getVars;
urlLoader.load(request);
Ugh. Ok, thanks to Theo (who I'll give credit for the answer because I didn't know about URLVariables) I went and checked every possible thing that could be wrong.
The real problem was that I do indeed have & in the original URL request. I was doing a string.replace() that of course only hits the first instance.
The problem was that in the debugger, Flash apparently helpfully converts & back to &! So I didn't see the bug. Thanks Flash!
If I had done a trace() on the output just to be sure (which I thought I had but I clearly hadn't) then I would have noticed this.