Copy link to clipboard
Copied
Hi all,
I am using Flash CS5.5 to create an app for IPAD, In this using php file to pass variables from DB(query)
If i pass the variables as static means it will retrive i IPAD, but dynamic means returns empty
EG:
Static php file: "passvars.php"
echo "username=flash&password=password";
From this i will get username and password in flash using URLloader
But dynamic-get value using query and return username and password
It will return ""(empty) as username
Please help me out to fix this problem. It was working fine in browser version
thanks in advance
sakthimani
Copy link to clipboard
Copied
Have you created a crossdomain.xml? I don't feel this should stop an AIR app (only web) but just to be sure you should put one in place.
I'm having a bit of a hard time understanding your English but you're saying if you explicitly echo "username=flash&password=password" it comes though fine, however when you access the DB and send back real values you're not receiving data?
Does your request sent to "passvars.php" require sending any information via GET or POST? Are you receiving any errors from the URLRequest and do you have any error handlers displaying these errors to verify?
Copy link to clipboard
Copied
Hi Sinious,
Sorry for my bad english. No i did't use crossdomain.xml. The process is
1. Word press login - first i am loged in wordpress blog created for my project.
2. From that login details a php file "passvars.php" will be loaded with query to select the user_login,password and id for the appropiate username and echoed
3. In flash AS3 project that "passvars.php" file will be loaded and get that echoed variables - Thier is no values passed from flash side
This is the way i am using in web version . The same thing i tried out for Air for IOS it returns the empty values.
PHP file will look like this:
<?php
include("wp-config.php");
$connection = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
$db = mysql_select_db(DB_NAME,$connection);
$wpOptions = mysql_query("select option_value from ".$table_prefix."options where option_name = 'siteurl'");
$wpOptions = mysql_fetch_array($wpOptions);
if(isset($wpOptions['option_value'])){
$siteurl = $wpOptions['option_value'];
}
$cookiehash = md5($siteurl);
if(isset($_COOKIE['wordpress_logged_in_'.$cookiehash])) $username = $_COOKIE['wordpress_logged_in_'.$cookiehash];
$username = explode('|',$username);
$username = $username[0];
$wpUsers = mysql_query("select ID,user_login,user_pass from ".$table_prefix."users where user_login LIKE '".$username."'");
$wpUsers = mysql_fetch_array($wpUsers);
echo "username=".$wpUsers['user_login'];
echo "&userid=".$wpUsers['ID'];
echo "&user_password=".$wpUsers['user_pass'];
?>
Yesterday i found that onething that is if i run the php file in browser it wil catch the username from cookie data and echoed the result.
From flash their is a struggle to catch the cookie date i.e., the $username = $username[0]; is null
And one more thing their is no login page in my flash side. The only way is wordpress login
Thanks
sakthimani
Copy link to clipboard
Copied
How can i get browser cookies data in AIR for IOS project in flash CS5.5
Copy link to clipboard
Copied
This is really more of a WordPress issue than Flash. A couple things to note..
AIR has a StageWebView which is the only real "browser" you have. Otherwise you have no hope of actually reading inside of any other kind of browser and as it is you can't read inside this browser at all by default. You'd need something like the UIWebView ANE to do that.
Most people embed the SWF in a webpage. By doing that they get to use JavaScript which handles cookies very well. If your cookie is set via JavaScript you have no real chance at getting it without a browser. The cookie needs to come in a response header to retrieve.
Here's a quick class you can try to see the headers returned from an URLRequest:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.HTTPStatusEvent;
import flash.events.IOErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class TestUR extends Sprite
{
public function TestUR()
{
var urlLoader:URLLoader = new URLLoader();
var urlRequest:URLRequest = new URLRequest();
urlRequest.url = 'http://www.cnn.com';
urlLoader.addEventListener( IOErrorEvent.IO_ERROR , onErrorHandler );
urlLoader.addEventListener( Event.COMPLETE , onLoaderCompleteHandler );
urlLoader.addEventListener( HTTPStatusEvent.HTTP_RESPONSE_STATUS , onResponseStatus );
urlLoader.load( urlRequest );
}
private function onErrorHandler( e:IOErrorEvent ):void
{
trace( "IOErrorEvent: " + e.target.data.toString() );
}
private function onLoaderCompleteHandler( e:Event ):void
{
trace("Complete");
}
private function onResponseStatus( e:HTTPStatusEvent ):void
{
trace( "Headers: " );
for each(var i:Object in e.responseHeaders )
{
trace( "name: " + i.name + " value: " + i.value );
}
}
}
}
What is most important is in bold. Adjust the location from cnn.com to your own file and see what cookies are visible in the response. PHP is perfectly capable of setting headers so it can send the cookie just fine.
My trace output from the above is:
Headers:
name: Server value: nginx
name: Date value: Tue, 06 Nov 2012 16:02:11 GMT
name: Content-Type value: text/html
name: Transfer-Encoding value: chunked
name: Connection value: keep-alive
name: Set-Cookie value: CG=US:RI:Providence; path=/
name: Last-Modified value: Tue, 06 Nov 2012 16:02:05 GMT
name: Vary value: Accept-Encoding
name: Cache-Control value: max-age=60, private
name: Expires value: Tue, 06 Nov 2012 16:03:06 GMT
name: Content-Encoding value: gzip
[SWF] TestUR.swf - 2,117 bytes after decompression
Complete
You can see there CNN is setting a location cookie when you visit it.
Copy link to clipboard
Copied
Thanks sinious . Yes the cookies are set via javascript.By using your code i got the some cookies value but the expected one is not traced Actually the project is for ipad. Is any way to do this for standalone app(without browser)?
Copy link to clipboard
Copied
If the cookie is set via JavaScript I'm afraid you're going to have to rely on an ANE to get your job done. You need an engine that can parse JavaScript, which is a browser. URLLoader/etc won't parse that for you. Being this is not AIR desktop you can't use HTMLLoader which was your closest bet supporting sending POST requests, handling JavaScript (to some extent) and having a manageCookies parameter.
As for iPad, I believe you'll need to go with a 3rd party solution, such as the iOS UIWebView ANE (commercial $65.99USD) which states:
With UIWebView native extension, all you need to do is link the ANE file in Flash builder/Flash Pro CS6 and start coding. You can call JS function from as3 or vice-versa, modify the DOM elements once the HTML is loaded, and even catch URI scheme in the page so you can do actions for mailto, skype, ftp and more.
I cannot confirm how well this ANE works but a solution that lets you access JavaScript is what you'll need to get at runtime created cookies. As you can see you can call functions (AS3->JS and JS->AS3). I'm assuming this means you can pass data back and forth as well, but make sure before you buy of course. Also be weary of relying solely on 3rd party products. If they go bankrupt, you could be left without a functioning app.
Otherwise I do believe you're up a creek unless you refactor that JavaScript into something returned by PHP or an URL. Chances are WordPress is just pulling async (ajax) info from a PHP file when you log in. You could locate what JavaScript is loading to get the cookie and patch yourself a custom way to get the data it returns. Remember, there's nothing special about WordPress. It's just a bunch of pre-written PHP. There's nothing stopping you from finding source code online to work with the login system, or alter it yourself.
Copy link to clipboard
Copied
Thanks lot sinious. I will try out your ideas
Copy link to clipboard
Copied
As an odd turnaround (due to StageVideo having unfixable bugs) I removed StageVideo and purchased that ANE. So far I can say the VideoPlayer works very well. I haven't tried communication with it yet as I have deadlines but if you get it and have any questions hit me up and I'll be able to help test.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more