My experience on my daily works... helping others ease each other

Showing posts with label Flex. Show all posts
Showing posts with label Flex. Show all posts

Thursday, March 15, 2012

Using Flex HTTPService to handle RSS with PHP


If you are using HTTPService in flex or using flash actionscript to handle RSS feed, you might found that not all RSS feed is supported by flex. This is due to flex can only access any feeds that have cross-domain.xml in their root directory of the web-server.

What happen if the website supplying the feed don't have cross-domain.xml or limited to certain website to access it by defined rules in the xml files. How to handle that?

I found a way with the help of php.

As usual, in your flex applications, you will have this line of code:

showBusyCursor="true" method="GET" resultFormat="object" />



and somewhere in your code, you have it called
myHttpSvc.url = "";
myHttpSvc.send();


and you php should contains this line of code:
class rssfeed{
    public function getRssFeed($urlAdd){
       return file_get_contents( $urlAdd );
    }
}

$sp = new rssfeed();
echo ($sp->getRssFeed(%_GET['urlToPass']));


That should do the trick. Now you can access any rss feed any feed into you flash / flex code without worrying about cross-domain.xml anymore.
Share:

Tuesday, November 9, 2010

Reading file using AS3

Taken from http://snipplr.com/view/2937/reading-a-file-asynchronously-with-actionscript-3/
 // Imports
 import flash.filesystem.FileMode;
 import flash.filesystem.FileStream;
 import flash.filesystem.File;
 import flash.events.ProgressEvent;
 import flash.events.Event;

 // Declare the FileStream and String variables
     private var _fileStream:FileStream;

     private var _fileContents:String;

     private function onCreationComplete():void // Fired when the application has been created
      {
    var myFile:File = File.appResourceDirectory;
    // Create out file object and tell our File Object where to look for the file

    myFile = myFile.resolve("mySampleFile.txt"); // Point it to an actual file

          _fileStream = new FileStream(); // Create our file stream

          // Add our the progress event listener
          _fileStream.addEventListener(ProgressEvent.PROGRESS, onFileProgress);

         // Add our the complete event listener
         _fileStream.addEventListener(Event.COMPLETE, onFileComplete);
 
        // Call the openAsync() method instead of open()
        _fileStream.openAsync(myFile, FileMode.READ);
      }

      // Event handler for the PROGRESS Event
      private function onFileProgress(p_evt:ProgressEvent):void
      {

        // Read the contens of the file and add to the contents variable
       _fileContents += _fileStream.readMultiByte(_fileStream.bytesAvailable, "iso-8859-1");

       // Display the contents. I've created a TextArea on the stage for display
       fileContents_txt.text = _fileContents;
     
       }

      // Event handler for the COMPLETE event
      private function onFileComplete(p_evt:Event):void
      {

     _fileStream.close(); // Clean up and close the file stream

      }
Share:

Reading File in Flex


var loader:URLLoader = new URLLoader();
// telling the loader that we are dealing with variables here.

loader.dataFormat = URLLoaderDataFormat.VARIABLES;

// This is an eventlistener, these are used all the time in AS3
// learn to use them, this basically tells flash to listen to a specific event
// and then call a specific function.
// in Our case we listen for the even called COMPLETE which means it will active
// a function called "loading" when our flash movie has completed.
loader.addEventListener(Event.COMPLETE, loading);

// Here we tell our loading which file to extract from.
loader.load(new URLRequest("content.txt"));

// This is the function that will happen when the eventlistener activates.
// basiclly it says that our text fields called content_1 and _2's text property
// should be equal to loader.data.var_1 and var_2 (as you might remember from the explanation above).
function loading (event:Event):void {
content_1.text = loader.data.var_1
content_2.text = loader.data.var_2
}
Share:

Chart with Flex SDK

Taken from Charts with the Flex SDK

I do a lot of work in both Flex Builder and with the Flex Module for Apache. For anyone who has been trying to figure out how to move your Flex Charting components over to the Apache Module (or mxmlc compiler), here’s a quick tutorial.

Note that $FLEX_HOME is the location of your Flex SDK install. Mine, for example, is “C:\Program Files\Adobe\Flex 2″.

1. Copy your charts.swc file from $FLEX_BUILDER_HOME/Flex SDK 2/frameworks/libs to $FLEX_HOME/frameworks/libs.

2. Locate your license key from Flex Builder. You can find this on the menu bar under Help > Manage Flex Licenses…

3. Edit $FLEX_HOME/frameworks/license.properties and add the following line:

charting=

You can keep the dashes in the key. After that, restart your Apache instance and you’re good to go.
Share:

Using Flex HTTPServices to handle RSS feeds

If you are using HTTPService in flex or using flash actionscript to handle RSS feed, you might found that not all RSS feed is supported by flex. This is due to flex can only access any feeds that have cross-domain.xml in their root directory of the web-server.

What happen if the website supplying the feed don't have cross-domain.xml or limited to certain website to access it by defined rules in the xml files. How to handle that?

I found a way with the help of php.

As usual, in your flex applications, you will have this line of code:

showBusyCursor="true" method="GET" resultFormat="object" />



and somewhere in your code, you have it called
myHttpSvc.url = "";
myHttpSvc.send();

and you php should contains this line of code:
class rssfeed{
public function getRssFeed($urlAdd){
return file_get_contents( $urlAdd );
}
}

$sp = new rssfeed();
echo ($sp->getRssFeed(%_GET['urlToPass']));

That should do the trick. Now you can access any rss feed any feed into you flash / flex code without worrying about cross-domain.xml anymore.
Share:

Monday, October 25, 2010

Date & Time formatting in Flex

What you need to know?
1. The format
Pattern Example
Year
YY 09 (Year Number Short)
YYY 2009 (Year Number Full)
YYYY 02009 (I have no clue why you would need this)
Month
M 7 (Month Number Short)
MM 07 (Month Number Full)
MMM Jul (Month Name Short)
MMMM July (Month Name Full)
Day
D 4 (Day Number Short)
DD 04 (Day Number Full)
Day Name
E 1 (Day Number Short)
EE 01 (Day Number Full)
EEE Mon (Day Name Short)
EEEE Monday (Day Name Full)
A AM/PM
J Hour in day (0-23)
H Hour in day (1-24)
K Hour in AM/PM (0-11)
L Hour in AM/PM(1-12)
N 3 (Minutes)
NN 03 (Minutes)
SS 30 (Seconds)

 2. How to format
     i. using date formatter => <mx:DateFormatter id="formatDateTime" formatString="MM/DD/YY" />
    ii. calling date formatter => formatDateTime.format(YourDate);
Share:

Saturday, October 23, 2010

State & Transition in Flex - Simple component to make your flash apps look superb

I love to use this two component in flex @ flash (for latest version of Adobe Flash programming language). It makes your simple and dull presentations looks marvelous, superb, fascinating, etc... BUT DEPENDS ON YOUR CREATIVITY TOO... :)
Here are the extracted code from my program.. just part of it if anyone wonder how to use this :)

Share:

Friday, October 22, 2010

org.xml.sax.SAXParseException: Content is not allowed in prolog.

Today while testing my flex applications and try to read xml files using BlazeDS which calls my java class I got this weird errors. When I ran it and test it out on Netbeans or Eclipse, it runs without any issues. But when I port into my webserver (running tomcat), this was pop-up. I run through google looking for solutions. Guest what I got, many of them saying that there is parsing issues when you are using either XML with encoding UTF8 or UTF16. There is a space before your XML starting point

I've try formatting it, validate it and nothing seem correct. and continue to get this errors
Catch Exception XmlConfigReader.readFileColl: Content is not allowed in prolog.
org.xml.sax.SAXParseException: Content is not allowed in prolog.
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)...

After when through a complete checking on my code, then I realize something... there is issues on my code, it does not find the file as the path is in complete. It point out to folder and not the file thus it is reading a complete folder and just grab the first file and read it. That is why it keep on getting the problem. So guys, if you are getting this problem, check your file and the path it is reading first. :)
Share:

Tuesday, May 12, 2009

Silverlight still behind flex

Is it true? yup, from my view... silverlight still can't overtake flex as no.1 RIA although they have many supporters and developers and programs compare to flex. WHY? I've lots of reason for that and here it few of them:
1. Good IF YOU HAD COMPLETE System Development team comprise of System Architect, System Analyst, System Developer, and GUI Designer plus all of them understand their roles very well, plays their roles very well, and have the same understanding on system being developed. Else, you'll wasting your time on development if both developer and designer cannot work together.

2. Good if you have very powerful development machine as it needs different tools/IDE to develop a simple applications compare to Flex which use only 1 IDE.

3. You had to set the size of your application at the beginning. You can't set it to 100% for the size compare to flex... therefore it was not really a comfort to developers and users especially when your client machine window size is vary from one to another...

that's all for now... wait till i found others silverlight problem...
by the way... I'm not againts silverlight... just comparing which tools the best as I'm using both
Share:

Sunday, December 28, 2008

Flex vs Silverlight vs JavaFx

I'm not a hardcore programmer with skill to write code without the need to explore internet searching for samples and code. With little skill, I've managed to do lot of programs and applications with the help of very good 'Sifu' @ Master; Google Search Engine.

I've done from basic applications, to client-server, till web applications. I've use VB, ASP, Java, JSP, Servlet, Applet, lots of Framework, C, C++, and latest is Flex (Adobe product). While building flex applications, I found out that flex (running application for flex is flash) do have major problem; memory; which until I wrote this, there is no strong solution to resolve that. It is very easy to develop using flex and it is nice when displayed to your desktop. Lots of customer I deal with do like the layout and presentation. However, when the application has a lot of functions; for example a HR System with Statistics and Analysis; then it will used lots of client memory. That does not stop there. Everytime a user move the mouse on the application and there is effect put on it, the memory will keep on increasing till exhausted. There was solution that is using System.gc(). However it does not help a lot.

Then, I look for alternative for that and found 2 competitor; Silverlight (from Microsoft) and JavaFx (Sun). Both are good at handling memory especially JavaFx. However, to lazy programmers and non-hardcore like me, the code and to write applications with either one of it is very difficults compare to Flex. And to add to that, you can't just install and build Silverlight, there is lots of software, runtimes, and the worst license that you need to have. Compare to JavaFx (JDevelopers or Eclipse is free) and Flex (using Flex SDK and Eclipse is free). Just take a look at their code in build simple Hello World applications and compare, it seem that Flex contains much lesser code and much easier to build and understand.

However, due to memory usage is a bit concern to me, I had to learn either Silverlight or JavaFx. Hope Flex will come out with better solutions A.S.A.P or they will lose to their competitor.
Share:

Friday, July 25, 2008

5 advice for developing RIA and WEB application in Flex

1. Avoid embed containers inside other containers. Reducing use of relative size and relative position
When the element size in container is described by percent, any change of the size or postion will take the re-position for all subset in container. The calculation will be great if the level of embed is deep.

2. Using lightweight containers like Canvas As far as possible
Canvas is the smallest container and only support absolutely positioin. Most time it could instead HBOx and VBox. Besides, Canvas is a first choice for us when custom containers. It has basic container function and good expand ability.

3. Avoid using large components like DataGrid, AdvancedDataGrid
Large components have powerful function but need high requirement for memory and CPU. Because of the complexity, it is difficult to realize the skin, patterns and itemRenderer.

4. Using paging when deal with data
When using data type control, as far as possible to minimze the amount of showing data. For example Tilelist, it will create all the data whether need or not. It will waste large resoures. When ViewStack 、TabNavigator, etc. dealing with element, data will not be created until they’re shown first time. The unnecessary cost will be avoided.

5. setStyle and styleName
In fact,the skin of Flex components is a visual element. In process of components initialization, they will use current style(for example:styleName) to finish all the skin elements.If we reset the style, the size of components by setStyle, the postion will also be adjusted. Link to the first point, if components in a deep level embed container will cost large calculation.

Taken from ntt
Share:

About Me

Somewhere, Selangor, Malaysia
An IT by profession, a beginner in photography

Labels

Blog Archive

Blogger templates