Welcome, Guest. Please login or register.
Did you miss your activation email?
02/07/12, 09:06
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  General
| |-+  Flex, Air, FlashBuilder, Catalyst (Moderators: ..:: Mazhar Hasan ::.., kofi addaquay)
| | |-+  Flex GuestBook Tutorial (so easy even birds can sign)
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 Print
Author Topic: Flex GuestBook Tutorial (so easy even birds can sign)  (Read 18490 times)
Andresss
Systems Administrator
*****
Posts: 738


check me out at www.asb-labs.com/blog


View Profile WWW Email
« on: 06/20/07, 23:00 »

UPDATE:in order to understand AMF objects and/results please refer to this post written a while ago (http://www.flash-db.com/Board/index.php?topic=11954.0)

Flex 2 Guestbook V.2 by Andres Santos (so easy even birds can program)
Starting with flex is just as easy as creating a web page, although flex can be compiled “on the fly” which means it can be compiled from a web server when a user request a swf file;or can be compiled or “packaged” in a swf file and deliver it as a stand alone swf application, and this is our case, we will be delivering our Flex guestbook as standalone swf of course embedded in a web page.

Highlighted points of this tutorial
Get started
Get in touch with flex and comonents
Use AS as JS
Use AMFPHP1.9 with flex
The Flex 2 Guestbook

FILES HERE (files contain main mxml,amfphp xml and mxml component read below)
(in order to run the files, you need to create a new project called “guestbook” and replace the main mxml for the one in the zip, also copy all the files into the project folder A working example with files can be found here:http://www.asb-labs.com/blog/flex-2-guestbook/)

So What the heck I need?
Good question! What is needed to get started right now and with no knowledge of Flex 2?, first download and install the latest version of flex 2 (current 2.0.1); once you downloaded be sure of installing it (lol).

Get started
As I mentioned before, Flex is as easy as creating a webpage, in order to “understand in a Christian way” flex instead of strange flow charts just compare it against a web page, how serious web pages are made?, they use the following schema (yep I know schemas wack but this one is easy):

Code:
<html>
<head>

<script language="JavaScript" type="text/javascript">
<![CDATA[
//something of JS here
]]></script>
</head>
</html>

The only difficult part to interpret are the JavaScript tags, the rest is as easy as turning on the TV, you have a TV right?
It is all the same with flex, in a plain html page you have only one <html> tag that tells the browser where starts and finishes the page the head is used to store metadata and code (remember a page is not ‘code’ are just tags) The same code from the previous example can be easily translated into flex as:

Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[

]]>
</mx:Script>
</mx:Application>

As you can see both codes share its structure, the flex version of the code adds an xml tag but that must go in all flex documents so it can be considered as useless, the <mx:Application> tag is the same as <html> and just one is allowed across the entire project, and the script tag extends as in a page its capabilities so you can perform a “low-level” control using instead of JS, ActionScript 3.

Get in touch with flex
Well I already introduced you to the basic knowledge of flex now open up flex and:

•   Create a new PROJECT not file nor component, Project.
•   In the wizard dialog choose the first option, it is called Basic (this will be the option almost for any purpose)
•   Give it a name and press finish

Flex will automatically show you the “design view” or “code view”. If you are not in the code view then change tothis view from the upper-left bottom on the corner of the project.
Once you get the code view you will be able to edit,remove,control or add new code hints, as an example add this code:

<mx:Button label="Button"/>

That will force to the design view to create a new component called Button, and as you can see the syntax is very similar to an html button, now switch to the design view and you will see a button that is the same as dragging it into your stage or workarea.
Play with the components adding them to the stage and also Seeing its corresponding tag.
You can access properties of each component or each tag just by bar-spacing once andit will popup some properties you can use.

Use AS seamless as JS
JS is a great tool for web pages because you access properties of any element on screen and perform certain actions with those properties;in Flex instead of using JS you use the AS3 language (yes flash language) to extend Flex behaviours. In order to do that you need to have the <mx:Script> tag if you do not have it then the AS code you write will be ignored and will output errors at compile-time.
Now write the Script tag and write this code:
Code:
<mx:Script>
<![CDATA[
Import mx.controls.Alert;
Public function createAlert():void{
Alert.show(“Andres says hi”,”Helloworld”);
}
]]>
</mx:Script>

When using AS functions you need to tell whether they are public or private and if they return something (use void if no returning data is sent). With the code we wrote we can say we have finally integrated Flex “with” flash BUT we need to call that “createAlert” function, and that can be called from our first button by adding the “click” handler

<mx:Button label="Button" click=”createAlert()”/>

If you added more buttons then lets define its “unique name”, remember the flash old school? When you had to give an instance name? well in flex happens the same, you have to give an instance name by adding “id”:

<mx:Button label="Button" click=”createAlert()” id=”fbtn”/>

YOU ARE DONE, now you can publish your work and see that it actually does something(press CTRL+F11)

Use AMFPHP1.9 with flex
(for more information about AMFPHP check jorge’s tutorials about this, I did not add how to call a method for that plz check the mxml so you can easily understand that part, about handling roles check my blog: http://www.asb-labs.com/blog/2007/05/19/amfphp-19-beta-2-using-roles/)
ALERT:this new release of amfphp doesn’t use tableMethod (in case you think I missed it)
AMFPHP is a great tool for sending and requesting data easily and fast, and flash wouldn’t be the same without it nor Flex. In order to get and send data to AMFPHP you have to copy this code in your application:
Code:
<mx:RemoteObject id="lservice" source="userLogin" destination="amfphp" fault="{onServiceFault(event)}" showBusyCursor="true" >
<!-- here goes the methods of the AMFPHPclass expressed in flex -->
<mx:method name="loguser" result="{onMethodResult(event)}">
</mx:method>
<mx:method name="logitout" result="{onMethodResult(event)}" >
</mx:method>

</mx:RemoteObject>

Source means the name of the service in the AMPFPHP “services” folder and loguser and logitout are public or remote methods inside the service. The “onMethodResult(event)” means the function to call when AMFPHP returns data after calling any of the methods in the service (look that bothhavethe same function withinflex, but you can have different functions).
Then add an xml file to the root folder of your project usually:

Documents and Settings\<user>\My Documents\Flex Builder 2\<project name>

This xml is:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<services-config>
        <services>
                <service id="amfphp-service" class="flex.messaging.services.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage">
                        <destination id="amfphp">
                                <channels>
                                        <channel ref="amfphpId"/>
                                </channels>
                                <properties>
                                        <source>*</source>
                                </properties>
                        </destination>
                </service>
        </services>
        <channels>
                <channel-definition id="amfphpId" class="mx.messaging.channels.AMFChannel">
                        <endpoint uri="http://www.your_site_url.com/amfphp/gateway.php" class="flex.messaging.endpoints.AMFEndpoint"/>
                </channel-definition>
        </channels>
</services-config>
Save this file as “services-config.xml”, finally right click on your project name (in the navigator panel, on your left) and click on properties, then in the dialog click on “Flex compiler” (the left column) and where it says:

-locale en_US

Add this:
-locale en_US –services services-config.xml

And apply changes, now YOU ARE DONE setting up AMFPHP with flex!!
*The Flex 2 Guestbook*
If you followed the entire tutorial you are now ready to understand everything I will say from now on and of course you are now a certified Flex member (lol), but I’m talking serious guys if you followed the tutorial you will discover that using flex will be easier as programming a page or an entire site.

The only thing I didn’t mention is that the guestbook is using a compenent extension, in flex you can extend components just by opening a File|New|mxml Component, instead of creating an AS class extending the component. This component extensions are considered by flex as MovieClips (not really but for you to understand the concept) you call it as you named the file as easy as that, so the guestbook uses “commentForm.mxml” that is a component extension of the “TitleWindow” component (yes it is extended using tags and using AS3 too).

NOTE FOR FLASH PROGRAMMERS: The root is not available in flex, so how can you work with levels? If you want to access the <Application/> level (the root level) use a reference to it (is like a constant) mx.core.Application.application.your_function_or_tag

And that has been all guys, if you reached till this part then you can modify the guestbook with no problem at all, hope you have enjoy this tutorial and if you have any doubts please post them in the flex forum and surely someone will try to help you.

Andres Santos
« Last Edit: 06/21/07, 08:51 by Andresss » Logged

halemos de flash en espaņol!....wondering about crazy flash experiments?
..:: Mazhar Hasan ::..
Moderator
Systems Administrator
*****
Posts: 828


Cheers


View Profile WWW
« Reply #1 on: 06/20/07, 23:36 »

nice work man
Logged

Your wish is my command
Andresss
Systems Administrator
*****
Posts: 738


check me out at www.asb-labs.com/blog


View Profile WWW Email
« Reply #2 on: 06/21/07, 08:31 »

:-D thanx Mazhar....
Logged

halemos de flash en espaņol!....wondering about crazy flash experiments?
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #3 on: 06/21/07, 18:56 »

Hi Andres

Sorry for delay, I'm currently in Florida, USA, visiting my family. Will put togheter the all thing on tutorials section on July when I come back

Jorge
Logged

Andresss
Systems Administrator
*****
Posts: 738


check me out at www.asb-labs.com/blog


View Profile WWW Email
« Reply #4 on: 06/21/07, 19:33 »

yep no problema boss
Logged

halemos de flash en espaņol!....wondering about crazy flash experiments?
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #5 on: 07/05/07, 16:35 »

Hi Andres

I have published the tutorial here http://www.flash-db.com/Tutorials/flexguestbook/

I have done a few changes:

- When sending the form, hide it so when you close the pop-up you return to the main screen. Closing both windows is anoying
- If the user post an image, hide the default one and show it if there's no image on the POST, if not they overlayed
- I have added a setup.php file to create the database (the sql.txt remains also) as an easy way to setup the DB part

Check it out and let me know whatever error you find

Thanks
Jorge
Logged

Andresss
Systems Administrator
*****
Posts: 738


check me out at www.asb-labs.com/blog


View Profile WWW Email
« Reply #6 on: 07/05/07, 17:39 »

hi Jorge, yep looks great, i say it flash-db rocks!! :-D
Logged

halemos de flash en espaņol!....wondering about crazy flash experiments?
Flasher111
Server what's that
*
Posts: 5



View Profile Email
« Reply #7 on: 07/15/07, 07:14 »

hi@all
i am new on this Forum!!
first of all thanks for this great Guestbook!!! Grin I`ll test it on this Site
http://www.flash-db.com/Tutorials/flexguestbook/
and now i have tried it on my own Site but it won`t work. I use the Server from
ohost.de and now my question ist it posible to run this Guestbook on the ohost.de
Server??

sry for my bad english
and thanks for help
« Last Edit: 07/15/07, 18:29 by Jorge Solis » Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #8 on: 07/15/07, 15:40 »

Post the URL to take a look

Jorge
Logged

Andresss
Systems Administrator
*****
Posts: 738


check me out at www.asb-labs.com/blog


View Profile WWW Email
« Reply #9 on: 07/15/07, 16:42 »

hey hi flasher111 and welcome aboard!!!! well by itself the guestbook won't work, you need first to upload AMFPHP a very known tool for interchanging data between the server, point the guestbook to AMFPHP and then you should be able to run the flex guestbook!!
Logged

halemos de flash en espaņol!....wondering about crazy flash experiments?
Flasher111
Server what's that
*
Posts: 5



View Profile Email
« Reply #10 on: 07/16/07, 10:17 »

thanks for your fast answers i try it first to install it and if i have any problems with the installation is ask
« Last Edit: 07/16/07, 10:25 by Flasher111 » Logged
Flasher111
Server what's that
*
Posts: 5



View Profile Email
« Reply #11 on: 07/16/07, 13:03 »

sry but i don`t know how i install amfphp. I upload all files in the root. And now i don`t know what i had to do with the debuggateway.php and the gateway.php. Does anybode tried to install amfphp on a ohost.de or funpic.de server?? here is the url from the Server:

http://cebit.ce.ohost.de/
« Last Edit: 07/16/07, 13:05 by Flasher111 » Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6161


View Profile WWW Email
« Reply #12 on: 07/16/07, 13:26 »

It seams to be working ok Wink

Justz place your services into the amfphp/services folder
Logged

happy flashing
Cool
Ronald
Andresss
Systems Administrator
*****
Posts: 738


check me out at www.asb-labs.com/blog


View Profile WWW Email
« Reply #13 on: 07/17/07, 12:00 »

hi Flasher111!! yep look into the files (the ones i uploaded or jorge's uploaded files) there is a folder called AMFPHP inside there is a folder called services, and that is exactly the same path you have to install in your AMFPHP folder.....now if you look in the tutorial you will also see that your site address must be changed from the services-config.xml ;_D

cheers!!!
Logged

halemos de flash en espaņol!....wondering about crazy flash experiments?
Flasher111
Server what's that
*
Posts: 5



View Profile Email
« Reply #14 on: 07/21/07, 12:05 »

hi Andresss,
i hope that i have all installed correctly but the guestbook won`t work. In the services-config.xml i addet the line

http://cebit.ce.ohost.de/gateway.php

If i start the guestbook a error popup appears.

you can show all datas on http://www.cebit.ce.ohost.de

thanks for your help
Logged
Pages: [1] 2 Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!