I am currently researching various web interactions in Flex 4.  The goal is to create a Flex/Flash client which provides secure user login to a database connection with (probably) Java or (maybe) PHP on the server side. Further, the goal is to not use Flash Builder, which is a commercial program. (I am using FlashDevelop instead. Please see this post for my opinions on this issue.)

This post will be a sample of Flex 4 code as I go through this learning process.

Step 1:  Connect to Something.

Here is the initial blog post about connecting to an RSS feed. This is an AIR app, and does not work as is (as of this posting). (See below for working AIR Flex 4 code.) http://www.riacodes.com/flex/desktop-rss-reader-with-air-flex

I will be modifying this later to make it Flex 4 only (not AIR), or else noting why that can’t be done.

AIR RSS Reader:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        backgroundGradientAlphas="[1.0, 1.0]"
        backgroundGradientColors="[#000000, #000000]"
        creationComplete="RSSFeed.send();"
        width="700"
        height="450"
        viewSourceURL="srcview/index.html"
>

        <!-- Style needed a namespace reference. -->
        <mx:Style>
                @namespace "mx.*";

                DataGrid {
                   alternatingItemColors: #cccccc, #eff1f2;
                   rollOverColor: #999999;
                   textRollOverColor: #ffffff;
                   selectionColor: #666666;
                   color: #000000;
                   textSelectedColor: #ffffff;
                }

                Button {
                   color: #ffffff;
                   themeColor: #333333;
                }
        </mx:Style>

        <mx:Script>
                <![CDATA[
                        import mx.rpc.events.ResultEvent;
                        import mx.collections.ArrayCollection;

                        [Bindable]
                        private var datas:ArrayCollection;

                        private function resultHandler(event:ResultEvent):void{
                                datas = event.result.rss.channel.item;
                        }

                ]]>
        </mx:Script>

        <!-- Have to escape the ampersand character. -->
        <mx:HTTPService id="RSSFeed" url="http://events.unl.edu/cropwatch/upcoming/?format=rss&amp;limit=100"
                showBusyCursor="true"
                result="resultHandler(event)"/>
        <mx:DataGrid id="news"
                dataProvider="{datas}" width="650" height="200">
                <mx:columns>
                        <mx:DataGridColumn dataField="title" headerText="Title" width="400"/>
                        <mx:DataGridColumn dataField="pubDate" headerText="Publication Date"/>
                </mx:columns>
        </mx:DataGrid>
        <mx:TextArea htmlText="{news.selectedItem.description}"
                height="150" width="420"/>
        <mx:Button label="Read Full Story"
                click="navigateToURL(new URLRequest(news.selectedItem.link));"
                enabled="{news.selectedItem!=null}"
                styleName="Button"/>
</mx:WindowedApplication>

Step 2: What is going on, exactly? Where is that stupid script/SWF?

Ok, so it’s clear I have forgotten my rudimentary PHP rules. Sigh.

I am turning to this post for help. I skipped down to the section that talks about remote database calls, and realized that I am having server issues. To expedite my learning curve, I am relying on FlashBuilder for CS5. However, it expects a local database and website, or else admin access to a remote file server as if it were a mapped drive. I think. Difficult to figure out, but I don’t think I have permissions, and FB won’t do FTP. So I was just going to manually post everything to the remote server, but had to install a basic web host on my local machine to get FB to output the files and use PHP. Just work, dammit!

Ok, tomorrow I will see if I can get things working better. I am going to put the default Zend on the remote server, and post the output files, and make things work. Right?

It’s not tomorrow, but this post describes how everything Zend works with cPanel. Here is another view of that post’s info:

  1. Download Zend Framework.
    • Note: Adobe FlashBuilder will install a local copy of Zend on your computer’s local server (if you have one). You can just use that install of Zend Framework instead of downloading a new one.
    • Get Zend Framework from zend.com and extract the contents to your local disk.
    • Extract ZendFramework-XX.tar.gz and rename ‘ZendFramework-x.x.x’ folder to /ZendFramework.
  2. Upload your local /ZendFramework folder to cPanel somewhere within your website
    • E.g., /home/cPanelUsername/public_html/ Copy down the name of that directory.
    • Note: Make sure FTP transfers the files in binary mode (BIN).
  3. Display and record your PHP directory information.
    • Create a file ‘info.php’ with the following line in it:
      <?php phpinfo(); ?>
      
    • Visit your site and open info.php.
    • Make a note of the DOCUMENT_ROOT value.
    • Make a note of the include_path value.
  4. Create a local php.ini file for your Flex pages.
    • Create php.ini file in the site folder where you are going to be running Flex. E.g., public_html/FlexTests/php.ini.
    • Add your Zend Framework library path in the include path variable include_path, and turn on allow_url_fopen, and allow_url_include in this php.ini file: , allow_url_fopen and allow_url_include functions. E.g.:
      include_path = ".:/usr/lib/php:/usr/local/lib/php:/home/cpusername/public_html/Zend/library"
      allow_url_fopen = On
      allow_url_include = On
      
  5. Tell Apache that it is ok to use your php.ini file.
    • If there is no .htaccess file in your site’s Flex directory, create a new text file called .htaccess. If there is one there already, open that .htaccess file.
    • Within the .htaccess file, add this line:
      SetEnv PHPRC /home/cpusername/public_html/php.ini
      
  6. Test the Zend install.
    • In your site’s Flex directory, create a testZend.php file. Add the following code:
      <?
      //require_once 'Zend/Version.php';
      require_once 'Zend/Mail.php';
      $mail=new Zend_Mail();
      //echo Zend_Version::VERSION . "\n";
      echo 'It is working';
      ?>
      
    • Go to your website using the browser, and access your Flex directory: http://www.yourdomain.com/FlexTest/testZend.php
    • It will show “It is working” message if everything goes well.
    • Note: You can use the commented code to show the Zend Framework version number instead of Zend_Mail(), which doesn’t give you any feedback.

I think that is enough for today. It was a pain trying to figure out that I needed to search for this . . . pursuing the system admin, suggestions, failed attempts, etc. So more testing tomorrow (or soon).

– 30 –

Advertisements