A really, really simple Services + AMFPHP example using Flex

public
group: Services
averageyoungman... - Sun, 2007-02-11 20:11

Hello,

Many seem to be chomping at the bit for examples, and seeing as I've got this working I figured I might as well post one. This is about as simple as you can get in terms of retrieving data from Drupal, via services.module, in Flex:

*NOTE: This is only an example of getting the gateway working with Flex. Nothing more. Please let me know if I have erred anywhere in my description. Also note that I used an example by Alessandro Crugnola as the basis of this example. His example is not Drupal-specific, but it can be found here: http://www.sephiroth.it/tutorials/flashPHP/flex_remoteobject/index.php

*ALSO NOTE: In my settings for the services module I have turned off the options for use keys and use sessid. This is because I wanted to present the simplest working example.

My Setup:
• OSX 10.4.8 (Intel)
• Apache 2
• PHP 5.2.0
• MySQL 5.0.33

What you need on the Drupal end:
Drupal 5.x
AMFPHP 1.9 Beta 2 (UPDATED - 1.9 Beta 2 now supports Services override requirements.)
AMFPHP module (I am using HEAD)
Services module (I am using HEAD)
• At least one node saved to your DB to retrieve

What you need on the Flex end:
• Flex Builder 2
• A Flex Project or equivalent AS3
• A services-config.xml file for your project (see below)
• A Flex compiler directive to include the services-config.xml file in the build
• An instance of a RemoteObject with which to call a service

Everyone probably already knows how to install the Drupal modules, so I won't go over that. Gory details follow:



1) Make sure AMFPHP 1.9 Beta 1 is in the root of your installation of the amfphp module. The path to it should be: your_drupal_install/modules/amfphp/amfphp

2) Confirm AMFPHP is working. To do this go to administer->site building->services and click on the AMFPHP - /services/amfphp link. If it's working properly you should see something like this:

amfphp and this gateway are installed correctly. You may now connect to this gateway from Flash.

Note: If you're reading an old tutorial, it will tell you that you should see a download window instead of this message. This confused people so this is the new behaviour starting from amfphp 1.2.

View the amfphp documentation

If you get an error make sure you have the correct beta I noted above.

3) Once you've confirmed it's working, create a new Flex project of type "Basic". I called mine AMFPHPTest.

4) Now create a new file anywhere in your project and call it services-config.xml. I created a folder in my project called "services" and put it in there.

5) In this file, you'll want the following. You will need to change the endpoint uri to reflect the location of your own install of the amfphp module:

<?xml version="1.0" encoding="UTF-8"?>
<services-config>
  <services>
    <service id="amfphp-flashremoting-service"
                 class="flex.messaging.services.RemotingService"
                 messageTypes="flex.messaging.messages.RemotingMessage">
            <destination id="amfphp">
                <channels>
                    <channel ref="my-amfphp"/>
                </channels>
                <properties>
                    <source>*</source>
                </properties>
            </destination>
        </service>
    </services>

    <channels>
        <channel-definition id="my-amfphp" class="mx.messaging.channels.AMFChannel">
            <endpoint uri="http://localhost/d5/services/amfphp" class="flex.messaging.endpoints.AMFEndpoint"/>
        </channel-definition>
    </channels>
</services-config>

6) Now add a compiler directive for the services-config.xml file you just created. To do this, do the following:

  1. Right click on your project in Flex Builder and select "Properties".
  2. In the Properties dialog, click on "Flex Compiler".
  3. In the "Additional compiler arguments" textfield, you need to add an additional directive telling Flex the location of your services-config.xml file and its location on your machine. In my case this file is in my default Flex Project location, and my directive looks like the block below. What I added starts with "-services":
  4. -locale en_US -services "/Users/my-user-name/Documents/Flex Builder 2/AMFPHPTest/services/services-config.xml".

    Note that in my case it was necessary to provide the full path to the file. This may not be necessary in your case.

  5. Click OK in the Properties dialog.
  6. If you get errors in Flex stating that the services-config.xml file can't be found, then the path to it is wrong. If it is wrong, an error will show up immediately in the "Problems" pane of Flex Builder. If you do not get errors, then your services-config.xml file is being compiled into your project when you click debug or run.

6) In the Application mxml file for your Flex Project, you're going to want something like this:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
  <mx:RemoteObject id="amfService" fault="faultHandler(event)" showBusyCursor="true" source="node" destination="amfphp">
        <mx:method name="load" result="resultHandler(event)" />
    </mx:RemoteObject>
  <mx:Script>
    <![CDATA[
        import mx.rpc.remoting.RemoteObject;
        import mx.rpc.events.ResultEvent;
        import mx.rpc.events.FaultEvent;

        [Bindable]
        public var resObject:Object;

        public function resultHandler(event:ResultEvent):void {
         // Do something
            resObject = event.result;
            result_text.text = "Success! The title of your node is: " + event.result.title;
        }

        public function faultHandler (event:FaultEvent):void {
         // Deal with event.faultstring, etc.
            result_text.text = "fault: " + event.fault.toString();
        }
    ]]>
</mx:Script>
<mx:Button x="250" y="157" label="nodeLoad" click="amfService.getOperation('load').send(1);"/>
<mx:TextArea x="10" y="36" width="319" height="113" id="result_text"/>
<mx:Label x="10" y="10" text="Result:"/>
</mx:Application>

Here's a quick piece-by-piece of the really important bits:

  1. Declare the RemoteObject and method with which we will connect to the node service. That looks like this:
  2. <mx:RemoteObject id="amfService" fault="faultHandler(event)" showBusyCursor="true" source="node" destination="amfphp">
            <mx:method name="load" result="resultHandler(event)" />
        </mx:RemoteObject>

    • The ID is local to the flex project, specific to the RemoteObject, and is not associated with our services-config.xml
    • The Source is the node service
    • The destination matches the destination ID of the service we declared in services-config.xml
    • The method name is the method of the node service we want to call
    • The rest should be relatively self-explanatory
  3. Import the classes / packages we need. That looks like this:
  4.         import mx.rpc.remoting.RemoteObject;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.events.FaultEvent;

  5. Declare the button used to invoke the call to the service. That looks like this:
  6. <mx:Button x="250" y="157" label="Load that node!" width="79" click="amfService.getOperation('load').send(1);"/>

    • The click event uses the ID we gave our RemoteObject to first get the specific operation (method) we want to call and then send the request with a NID of 1. In my case this is a Drupal page with a title of "TestPage". You can change the NID to any node you have published.

The bits I didn't cover here are the event handlers for the RemoteObject and the textarea component that displays a fault or result. That stuff should be relatively self explanatory.

This works for me. I can not guarantee that it will for you, but by all accounts it should.

Once you have all these pieces assembled, you should be able to click the "Load that node!" button and see output of your node title. You'll just have the change the endpoint etc. that I mentioned above. If you want, email me and I'll give you my simple source. I can't attach it here. Please let me know if I've missed anything, it would be easy to.

NOTE: - Apologies to anyone who downloaded 1.9 Beta 1 and had issues. When this post was first created, AMFPHP 1.9 Beta 2 did not support the Services module's requirements. 1.9 beta 2 works in the context of these instructions without any modifications to file locations.

Nice

snelson's picture
snelson - Sun, 2007-02-11 20:21

Thanks for doing this. I have a couple of screencasts coming in the next few days.

Scott


No problem!

averageyoungman... - Sun, 2007-02-11 20:33

To the contrary, Thank You for getting this going. This is truly a spectacular addition to Drupal, and really exciting. Great work.

justin

Recipe Service Error

chand - Mon, 2009-05-25 14:11

I am following your screen cast for creating a recipe viewer with flex and drupal. I have a problem in it I am using drupal 6.12 but when I am going to make recipe_service.info and recipe_service.module then problem occured and I attached the file to this message of error. Please have a look on the file attached to this message for having the better idea of my problem. I dont want to use drupal5.x to solve this specific problem and the error is about the version incompatibilty and this occured only here the previous process goes very nicely.

I'll be very grateful to you for the great tutorials and also please solve this problem.

Thanks
chand

Try adding the line: core =

mrconnerton's picture
mrconnerton - Mon, 2009-05-25 15:32

Try adding the line:

core = 6.x

to your recipe_service.info file

Matthew Connerton
http://www.mrconnerton.com


problem is still there

chand - Tue, 2009-05-26 04:41

Thanks for responding but problem is still there, here my recipe_service.info file's content

core = 6.x
name = Recipe Service
description = Some sevices for recipes
package = Services - services
dependencies = services

before I don't have first line core = 6.x but now also the case is same nothing different.
Take a look on this problem please.

Thanks
Chand
chand.wasim@gmail.com

shortcut

snelson's picture
snelson - Sun, 2007-02-11 20:41

Instead of doing:

amfService.getOperation('load').send(1);

You can do:

amfService.load(1);

For this reason, I like to give my RemoteObjects an ID related to the service source, like "nodeService" or even simply "node".

Then, you can do:

node.load(1);

... clean.

Scott


what abut flash users?

gavri's picture
gavri - Mon, 2007-02-26 11:27

what if i wanted to implement this example or one similar to it using flash - how can i call to the node service?

thanks


A Flash example

averageyoungman... - Sat, 2007-03-10 16:55

Hey,

Sorry for the late reply. Here's an example using Flash 8 Professional / AS2:

// remoting
import mx.remoting.Service;
import mx.remoting.PendingCall;
import mx.rpc.RelayResponder;
import mx.rpc.FaultEvent;
import mx.rpc.ResultEvent;
import mx.remoting.debug.NetDebug;

mx.remoting.debug.NetDebug.initialize();

var tf:TextField = this.createTextField("field", 10, 0, 0, 200, 200);

var node:Service = new Service("http://localhost/d5/services/amfphp", new Log(), "node", null, null); // connect to remote service
var pc:PendingCall = node.load(1); // call service method
pc.responder = new RelayResponder(this, "getData_Result", "getData_Fault");

tf.text = "no response from server yet.";

function getData_Result( re:ResultEvent ):Void { // receive result
  tf.text = "response";
}

function getData_Fault( fe:FaultEvent ):Void { // receive fault
tf.text = "error";
}

Remember that this example is subject to Flash Player Security Sandbox restrictions. If you get an "Error Opening URL" error, you need to place the swf file within the domain in which the services reside, or create a cross-domain policy file that will enable the swf to issue the service call.

  • justin

Remoting component libraries required in Flash

bcswebstudio@drupal.org's picture
bcswebstudio@dr... - Wed, 2007-05-02 18:26

Note that a simple to install library of two Remoting components is required on the Flash end:
http://www.adobe.com/products/flashremoting/downloads/components/

I got "The class or interface 'mx.remoting.Service' could not be loaded." in my Flash8 output window on compile/run until I installed these components. First you install (see link above), then in Flash8 choose Window>>CommonLibraries>>Remoting, and drag both components onto the stage.


oh this is exciting!

bcswebstudio@drupal.org's picture
bcswebstudio@dr... - Wed, 2007-05-02 19:31

It works, it really works! The simple example calls the node load service, and the result, on success, can be seen by adding:
trace(er.response.title);
into the function getData_Result.

I've added your code snippet, mildly amended, and my other steps discovered to d.o handbooks:
http://drupal.org/node/113697


I've copied this example

denizengt@drupal.org's picture
denizengt@drupal.org - Thu, 2008-02-14 12:38

I've copied this example exactly, and Services + amfphp (under d5.6) appears to be installed properly. I've even had this working before under 5.1. I've installed and re-installed at least 20 times.

For some reason, now I can't get anything returned. If I use justins example above for Flash 8 Prof and AS2, the text fields are filled with 'undefined' in Flash CS3 (doesn't matter what node id I use either).

If I go into the service browser in Drupal, and open node.load and use an nid of 1, the correct data is returned. Does anyone have any idea on how to remedy this? It's driving me bonkers !

Mo of the Cloud Concept, Adelaide, Australia.

View my (aging) site @ http://www.reactiondynamics.com.


Thanks

Thatch - Fri, 2007-03-09 23:13

I appreciate you putting this together. It's a very simple introduction to getting the connections between flex and amfphp.... however, I seem to be even more simple than this tutorial.

Any chance you know what might be going on with my attempt? I am getting the following error returned.

fault: [RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed"]

Everything seems to be set up fine on my server. amfphp seems happy, I can step through the servers and send arguments and the like, but the above error persists.

Any thoughts?

Thanks again for your work on this,

Hmmmm...

averageyoungman... - Fri, 2007-03-09 23:56

Hey,

I haven't had a chance to look at the example and compare it with your
error message yet, but the first thing that comes to mind is that the
services-config file may not be getting compiled in properly, or there
is domething up with the channel/destination. Did you
add the services-config file to the compiler arguments field?

If I knew your context I might be of more help. My guess is it's
something in or related to the services-config file, considering that
the error is referring to the send portion of the RPC connection in
reference to the channel.

WHat does your services-config file look like?

  • justin

Thanks for having a think on

Thatch - Sat, 2007-03-10 00:22

Thanks for having a think on this...

I have played with the services-config file a bit as it appeared to be the problem to me as well but it seems alright. I altered the location in the compiler arguments to be both relative and absolute, purposely made it incorrect to make sure it would give me an error (which it does) I also changed the endpoint from my (virtual) domain location to the actual server domain location.

The services config file looks exactly like the one posted except with my install location.... (there are only 2 test nodes on this install)

<?xml version="1.0" encoding="UTF-8"?>
<services-config>
    <services>
        <service id="amfphp-flashremoting-service"
                 class="flex.messaging.services.RemotingService"
                 messageTypes="flex.messaging.messages.RemotingMessage">
            <destination id="amfphp">
                <channels>
                    <channel ref="my-amfphp"/>
                </channels>
                <properties>
                    <source>*</source>
                </properties>
            </destination>
        </service>
    </services>

    <channels>
        <channel-definition id="my-amfphp" class="mx.messaging.channels.AMFChannel">
            <endpoint uri="http://skeesick.com/modules/amfphp/amfphp/gateway.php" class="flex.messaging.endpoints.AMFEndpoint"/>
        </channel-definition>
    </channels>
</services-config>

Aha!

averageyoungman... - Sat, 2007-03-10 00:50

I think it's your channel endpoint...

The amfphp module overrides the AMFPHP gateway in order to make the services directly available within the Drupal API. So your endpoint should actually be something more like:

http://skeesick.com/services/amfphp

If you look in services.module, you'll see a hook_menu entry with that path and a callback specified if I remember correctly. That callback is essentially the entry point for your service call. I can't be totally sure, but I think that's the problem.

  • justin

No Dice

Thatch - Sat, 2007-03-10 01:11

Well I was hopeful, but after changing (in several ways) the endpoint I ended up with the same error.

J

Damn

averageyoungman... - Sat, 2007-03-10 14:23

Are you logged in to your Drupal install?

I tested my own installation and Flex app while logged out of my install. I got the same error! So I logged in as the admin...and it worked again! I'm not sure what the connection is there, seeing as this simple Flex app does not send or require session or user information, but I can confirm that I get the same error when logged out. Try logging in and see what happens. Also, one other thing to check (if you're on a Mac running an install of Apache 2.x) is if the default install of Apache on the Mac in /usr/sbin is running. If it is, and you're attempting to use a different httpd, I believe this will cause problems.

If being logged out is the issue, that's definitely something I missed. So sorry about that. I also tested this by creating a generic user with virtually no priviliges, logging that user in, and running the Flex app. It works this way as well. So, interestingly, it appears that there must be at least one user logged in for the app to work. Not sure why.

  • justin

Done and Dusted

Thatch - Thu, 2007-03-15 11:21

Justin,

Thanks for all your help with this. You've gone above and beyond. I kept plugging away and figured out that it was a conflict with PHP4. I'm on 1and1 host and they run several PHP versions concurrently. I changed the htaccess file to make the site globally run PHP5 by adding the line AddType x-mapp-php5 .php alternately you can simply make your extensions .php5 on individual files to use 5 for just that file.

Once I made that change the original file worked fine. I appreciate all your help.

J

Flex/Drupal AMF only works if logged into Drupal.

ShawnW - Sun, 2007-09-09 17:42

I encountered this same issue. It seems that AMFPHP uses the User object in Drupal that only exists if someone is logged in. I added a block of code to my Flex app to do an automatic login of a generic user created for this purpose. Make sure the user has permission to access views.

CODE
public function init():void
{
LogIn();
}

public function LogIn():void
{
var request:URLRequest = new URLRequest("http://yourdrupalsite.biz/index.php/node")
var variables:URLVariables = new URLVariables();
variables.destination="node";
variables.name="drupaluser";
variables.pass="drupalpass";
variables.op="Log in";
variables.form_id="user_login_block";
request.data = variables;
request.method=URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE,LoggedIn);   
loader.load(request);
}

END CODE

You can do it without being logged in drupal

redben - Sat, 2008-03-15 14:53

Hi,
Just my 2 cents, if you want to access your services (through AMFPHP for instance), you can do the following :
1 - Log into you drupal site
2 - Goto Administer > User Management > Access Control
3 - Scroll down to "services module"
4 - Thick the "access services" checkbox for anonymous user
5 - Logout and give your flex app a test.
Theorically it should work. This would spear you the need for a generic user code block in your flex App.

By the way

I have been playing with the example a bit (and the article on http://devzone.zend.com/article/2660-Reading-And-Writing-Drupal-With-Fle...) . Tried to use the session ID an key and here is what i did to make it work :
1 - Administer > Site Building > Sevices > Settings
2 - Created a Key
3 - On the settings page, i checked "Use Keys" and "Use sessid"
Changed my flex app to the following :

<mx:Application creationComplete="initSession()" xmlns:mx="http://www.adobe.com/2006/mxml" >
  <mx:Script>
    <![CDATA[
      import mx.controls.;
      import mx.rpc.events.
;
      import mx.utils.ArrayUtil;
      import mx.collections.ArrayCollection;
     
      // The key that i created in drupal services. Change this to whatever your generated key is
      private var myKey:String = 'f7572c6e02856507c96c677d65fa3d96';
     

      // Call this before anything to get a session id. I chose to call it  on the application's creationComplete event
      public function initSession():void
      {
        drupalSystem.connect(myKey);
      }
     
      // Use the result to  get the session Id and send the add it to the login method parameters
      public function logMeIn(event:ResultEvent):void {
         
        drupalUser.login(myKey,event.result.sessid,'myusername', 'mypassword' );
      }
     
      public function userLoggedIn(event:ResultEvent):void {
        Alert.show( "Logged in" );
      }
     
      public function onFault(event:FaultEvent):void{
        Alert.show(event.fault.faultString, "Error");
      }
    ]]>
  </mx:Script>
 
  <mx:RemoteObject showBusyCursor="true" destination="amfphp" source="system" id="drupalSystem">
    <mx:method name="connect" result="logMeIn(event)" fault="onFault(event)"/>
  </mx:RemoteObject>  
 
  <mx:RemoteObject showBusyCursor="true" destination="amfphp" source="user" id="drupalUser">
    <mx:method name="login" result="userLoggedIn(event)" fault="onFault(event)"/>
  </mx:RemoteObject>
</Application>

A couple of questions

newdru@drupal.org - Wed, 2007-04-04 06:35

First let me say thanks to snelson and averageyoungman for sharing their knowledge. This is stuff a certain subset of users here are probably fairly interested in.

Now for the questions :-)

1) I still use flash mx2004 AS 2.0:

a) does the flash post example below apply to mx2004 / AS 2.0?

b) i'm assuming that for the flash post example below, the code presented would go in the mxml file and all the other code snippets / services config would remain the same. Is that correct?

2) the topic AMFPHP seems to be focusing on flex though the philwickam example that got the ball rolling is flash based. I personally have not ventured into flex yet and imagine that the majority of drupallers out there are probably more versed in flash/AS versus flex (though i could be wrong). meaning that the majority of folks interested in this are probably going to be looking for flash based examples. at least i am :-). Partly because it's what i know. Partly because i don't want to have to drop another couple of hundred bucks to get flex and learn yet another language when i can leverage the skills that i already have. So my thoughts, suggestions and questions related to this are as follows:

a) will there be more flash examples or at least an equal focus on flash versus flex with regard to these modules? i think that's where the majority of folks want to leverage your excellent work.

b) what's all the buzz about flex? should i be thinking about moving in this direction and making the investment? Is it supposed to augment flash or replace it?

I'm still having a hard time understanding what flex is i guess. I went to a local adobe group meeting a couple of months ago and from what i could tell, it appeared to be an AS generator that created bloated code. What i mean is that it seemed like it was a rapid app flash generator designed to allow non programmers to code AS (hence the code bloat) and generate forms and apps with predefined widgets? From what i understood it was pricey and targeted towards higher end corps that had the budget to buy the stuff (and lacked the coding experitise to simply code AS). At the time, my gut feeling was i'll let somebody else mess with this stuff. It's a waste. However, i must be wrong because i keep seeing "flex" pop up every where.

Somebody please set me straight. What is it that flex does that i should be excited about?

c) I read in one of the posts that you can get a free compiler for flex. that way you generate the xml files and compile the stuff without the slick interface. Is this feasible in the real world or do you really need the rest of the app/toolset?

d) assuming i'm going to jump and learn flex, anybody have a link or two to the holy grail of getting started with flex quick?

I mean jumping into the coding of meaningful examples quickly if you already have a background in AS 2 without wasting lots of time and also how to compile the code / set up the environment efficiently.

3) I've got Mx2004 and program in AS2. Soon after i bought that flash jumped to flash 8 with i believe hints of AS3. Now we've got a new version that just came out in CS3 and i believe that's AS3. I keep hearing about Apollo. AS3 is apparently pretty different from AS2. Now I've got flex on my horizon and god only knows what version that is at now and how it relates to the plethora of flash versions.

Can anyone in a paragraph or less sort all of this out or point to a good link :-)? (actually write as much as you desire!)

fwiw, i didn't jump to flash 8 because i had just dropped enough dough on the macromedia suite i bought at the time and it didnt' seem to offer much difference (although i really wish i had the flash 8 filters!). I just saw a preview of flash cs3 and the best feature was it's import features (it's now much easier to pull graphics in from ps) but other than that, it didn't seem that great to me.

a) So, am i going to be screwed if i stick with mx2004 and continue to program in AS2?

b) Will i be able to use AS2 with flex or does it use some other language?

c) AS3 is going to give me exactly what? (i'm starting to worry that if i don't start looking at AS3, i'm going to be left behind eventhough AS2 serves me fine right now)?

4) Screencasts! Yeah ... When are those coming? That would be really great..

Sorry for the long post but hopefully others have a lot of the same questions and share some of the same ideas. My thought is that by bringing them up, we can nip a lot in the bud for future posters.

thanks again for your contributions to this.

More about Flex

mikeypotter@drupal.org's picture
mikeypotter@dru... - Wed, 2007-04-04 14:04

Hey there:
I'm on the developer marketing team for Flex, so I think I can answer some of your questions.

Flex is a framework for building Flash applications. As you said, its pre-built ActionScript components that you can use to build a .swf file (same output as Flash, though Flex apps require FlashPlayer 9).

The reason that people are so excited about it is that it remove timelines and other tools that developers aren't used to (like the paint brush... :) ) It gives software developers a way to build real applications that get delivered via the FlashPlayer.

Flex is all ActionScript 3.0. ActionScript 3 is more advanced than AS 2, though a bit more complicated too. However, its screaming fast. Way faster than AS 2. If you're running into performance problems with AS 2, you should move to Flex or AS 3. If not, then don't worry about it.

You can download the Flex SDK, which includes a compiler and debugger, for free. You can also use Flex Builder, an Eclipse plugin, that gives you WYSIWYG editing for your Flex application, plus code completion, highlighting, autocomplete etc... That product is $499.

You can get more information from http://www.flex.org/php/

Mike


hey mikey

newdru@drupal.org - Wed, 2007-04-04 22:35

thanks for the reply.

I did a little more digging myself and combined with your replies i think i have a better understanding of flex now. But also a few more pointed questions:

fwiw, I rarely used the std flash ide / timelines period with mx2004. I mostly program AS2. So in that sense i'm using my current version of flash much like flex to build "real" applications. However, it seems that what you are saying is this:

1) Because flex is based on AS3, and the new flash player 9 is improved to take advantage of AS3, my swf apps now have newer capabilities that are already sitting in the engine (reside in the player) that can be exploited by AS3. I imagine that flash player 9 is also probably "heavier" then prior versions (e.g. larger file size) to accomodate the increased functionality. However, because it is only downloaded once, that allows your flex apps (swfs) to be lighter and not require as much download time but actually do more sophisticated stuff (e.g. the rendering is probably pushed more to the local player).

Would these be a (semi)correct statements?

2) Do you know current penetration of FP 9 and is there a link that keeps one up to date on those statistics?

3) How different is AS3 from AS2? Do you have any good links/books to recommend to make the transition for an AS2 programmer?

4) Without Builder, i imagine all the components are still available to me (i simply include x class and component is rendered at run time). Correct?

And if that's the case, if one simply loads the SDK, do you have a site link/section which gives good info (descriptions/live examples or at least imgs) of all the widgets/components so the developer can visualize them without Builder?

5) Did you guys build in tweening classes and sequences similar to fuse into flex? What are they called in flex (any links)?

6) Any upgrade path for MX2004?

7) wtf is apollo? ;-)

8) Finally, i understand that flex initially was a server based product. I completely understand the current "view" / incarnation of flex as a robust application environment based on AS3 and FP9. But with regards to server based flex, can you say anything about what that's all about currently if anything?

thanks for your time and input

Limited answers

averageyoungman... - Thu, 2007-04-05 14:15

Flash Player Penetration

Apollo is a cross-platform desktop runtime, capable of running Flex / AS3 applications.

As to question 4, you can use the Flex SDK with the Flex compilers and an IDE to create Flex apps without Flex Builder, although builder - IMO - is way more than worth the money. All the components etc. are documented in the LiveDocs.

AS3 is completely, totally different from AS2. However IMHO it is a far better, more complete implementation and programming language. Any complexities it adds are justified by what they can potentially yield for you as a developer. Also, from an architectural standpoint I think it makes a lot more sense. It is far more powerful than AS2 in just about every respect, and development is more inherently structured based on the differences and impovements.

There are robust tweening classes in AS3, but I myself am not aware of a Fuse-like sequencer equivalent. APE is looking rather promising though.

As to question 1, I'm not entirely sure what you're asking regarding the newer capabilities for existing apps. If they are written and compiled using AS3 then yeah, your apps have access to all the cool new features of Flex / AS3.

The ActionScript 3 Cookbook is a good transition book for moving from AS2 -> AS3. My recommendation however is to download the trail version of Flex Builder, read the docs, experiment, and consult books as is needed. There are also some Adobe-endorsed Flex specific books out there as well.

Good luck!

  • justin

Another thing

newdru@drupal.org - Wed, 2007-04-04 22:48

If i'm going to move to flash 9 and start doing some flex AS3 but simultaneouly still develop AS2 stuff, is there anyway to have my local browser still use more than one flash player version eg. (fp7 + fp8 + fp9 or some combo of those). e.g. once i install fp9 that replaces (uninstalls?) my prior fp version?

I ask because i imagine many folks out there still do NOT have fp9 installed. So i'd like to be testing in environments that my consumers will be using.

otoh, maybe fp9 is completely backwards compatible with earlier players (i imagine it is).

thanks

Yes, Flash Player 9 is

mikeypotter@drupal.org's picture
mikeypotter@dru... - Thu, 2007-04-05 14:31

Yes, Flash Player 9 is completely backwards compatible with Flash Player 8. You shouldn't have any problems updating your Flash Player.

Mike


Hey Mike I know your a Flex

chrismcintosh - Fri, 2009-05-29 03:58

Hey Mike I know your a Flex Guy over there, but any chance on getting someone from adobe to put together some docs on this. Seems still to be a lot of fuzziness around especially when it comes to Flash instead of Flex. I am personally running into an issue where I had an app that once worked, but now transitioning to a new host i am getting a BadVersion error and not much more to point me in a direction to go. Any good classes to trouble shoot something like that.

ServiceCapture/Charles

dazweeja - Fri, 2009-05-29 05:19

IMO the best troubleshooting tool you can use in these cases is an HTTP/AMF inspector like ServiceCapture or Charles. That way you can see exactly what is being sent to your server and what's coming back. They both have free trial versions.

Installation

pfouet - Wed, 2007-05-23 13:09

Good luck...
PfouEt

Error

newms - Wed, 2007-06-13 19:57

I am trying out the example above, but whenever I hit "nodeLoad" in the flex app I get the following error:

fault: [RPC Fault faultString="[MessagingError message='Unknown destination 'amfphp'.']" faultCode="InvokeFailed" faultDetail="Couldn't establish a connection to 'amfphp'"]

It looks like it's not picking up the amfphp service. I have amfphp, services modules and the gateway installed. Any idea what's wrong?

Similar to what's been

mhovey - Wed, 2007-06-20 16:06

Similar to what's been posted before, I'm getting this error:

RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed: url: 'http://www.tshovey.com/services/amfphp'"]

I've double checked all my code and I'm pretty sure everything is in line. Everything with Drupal is setup (views, services, amfphp) correctly yet I'm still running into this problem. I'm using 1and1 hosting, which I saw above, has a few issues with PHP4/PHP5 so I tried adding a line to my .htaccess to only enable PHP5 but I come up with a server error there. Any ideas?

Look at redben's comments

pushkar - Wed, 2008-12-03 17:15

http://groups.drupal.org/node/2768#comment-30865

The permissions is a big thing. If you have that correctly set up - that will solve a LOT of issues. :)

Solved: You have to have

newms - Tue, 2007-06-26 16:26

Solved: You have to have drupal installed in your webroot. That worked for me.

Flash Player 9

paysansan - Fri, 2007-07-20 12:29

Please, what are the great difference between Flash Player 9 and the 8? Thx. Pierre.

ActionScript 3 is supported in Flash Player 9 and above

Chris Charlton's picture
Chris Charlton - Fri, 2007-07-20 18:47

Flash Player 9 uses ActionScript 3 now, which processes 10x faster than ActionScript 2. It supports AS2 also. There's more video and hardware acceleration stuff now. Many more features, but there are just highlights.


Can't find globals.php (amfphp.module line 43)

LeeHunter's picture
LeeHunter - Tue, 2007-10-09 19:19

I've installed the Drupal amfphp module ok and the amphp 1.9 beta (modules\amfphp\amfphp) but when I click on the amfphp server or the services page I get the following error:

require_once(modules/amfphp/amfphp/globals.php)[function.require-once]: failed to open stream: No such file or directory in c:\xampp\htdocs\Drupal\modules\amfphp\amfphp.module on line 43.

This isn't too surprising really, since the globals.php file is actually in /amfphp/amfphp/core/shared/app. I tried just editing the amfphp.module file but this just produces a new error. Obviously, there's something I've missed in the installation, but I've repeated the instructions several times and wind up in the same place.


My bad. In the confusion

LeeHunter's picture
LeeHunter - Tue, 2007-10-09 20:27

My bad. In the confusion over the similarly named amfphp files, I wound up with the wrong version for amphp 1.9 beta. Looks ok now.


Service Browser doesn't load

LeeHunter's picture
LeeHunter - Wed, 2007-10-10 21:26

I seem to have everything installed correctly, but when I click "Load the Service Browser" link, it gives me a page not found. The application is also not finding the http://localhost/Drupal/services/amfphp URL.


I have the same problem

Juonio@drupal.org - Mon, 2007-10-22 12:36

It does this also when I try to install amfphp separated from Drupal. So I think the problem is in amfphp. Help needed! I'll try also to find answers on other forums handling amfphp.

Can this be a server issue?

Juonio@drupal.org - Wed, 2007-10-24 11:57

I got my service browser working. It can't open it directly through services module but if I use absolute link to the browser folder, it works.

Still, I can't get the connection to my flash application working.

Could this be a server issue?
http://drupal.org/node/141992

Can anyone tell a localhost server configuration that works with servers module and amfphp module. It would be nice if setting it up is easy. I use WOS-portable serverpackage. It has:

Apache 2.2.4 (Small edition)
MySQL 5.0.41 (Small edition)
PHP 5.2.3 (Small edition)

cant get it working

ven@drupal.org - Sat, 2009-03-07 23:28

When using the AMFPHP 1.9 beta 1 (the version downloaded from this page) i get the error:
Fatal error: require_once() [function.require]: Failed opening required 'modules/amfphp/amfphp/globals.php' (include_path='.:/usr/local/share/pear') in /xxx/modules/amfphp/amfphp.module on line 43

When i use the AMFPHP beta 2 (the version not recommended) it finds the globals.php, but then i get error

Fatal error: Uncaught exception ‘VerboseException’ with message ‘realpath(): Unable to access /xxx/services//’ in /xxx/modules/amfphp/amfphp/core/amf/app/Gateway.php:296 Stack trace: #0 [internal function]: amfErrorHandler(2 , ‘realpath(): Una…’, ‘/xxxxx…’, 296, Array) (... and lots of more errors)

[Edit]
Really never found out why it wasn't working, but it had to be something with the webhost/php setup, since none of these issues appeard with my new webhost.

i've attempted to get the

psi-borg@drupal.org - Fri, 2007-11-09 15:46

i've attempted to get the amfphp.module working to no avail. i followed the example closely and read through this thread for solution pointers, no joy. i've tried setting n for node.load(n) to several different node types, but continue to get the following fault msg:

fault: [RPC Fault faultString="Didn't receive an acknowledge message" faultCode="Server.Acknowledge.Failed" faultDetail="Was expecting mx.messaging.messages.AcknowledgeMessage, but received null"]

i'm also wondering if the flex-ajax bridge new to flex 3 at adobe labs might be a better way to wrap drupal into a flex application... any thoughts?

Exact Same!

flex_vixen's picture
flex_vixen - Thu, 2007-12-06 00:15

Hi guys,

I followed this to a "T" and get the same error that psi-borg posted. First a popup states an actionscript error "RangeError: Error #2006: The supplied index is out of bounds."

And then the result reads:

"fault: [RPC Fault faultString="Didn't receive an acknowledge message" faultCode="Server.Acknowledge.Failed" faultDetail="Was expecting mx.messaging.messages.AcknowledgeMessage, but received null"]"

Please help!


First...

averageyoungman... - Thu, 2007-12-06 13:25

I've updated this original post. Some of the problems people have been experiencing are the result of my not doing so earlier. AMFPHP 1.9 Beta 2 has been updated to support the requirements of the Services module, and I've been out of the loop for a bit. Nasty bike crash. Anyway, at the time the post was written Beta 2 did not work with the Services module. I tested the example above with 1.9 Beta 2 (which is now correctly linked in the post) and it works fine. No changes are needed save the change to using AMFPHP 1.9 Beta 2.

Apologies to anyone who experienced issues with Beta 1 as a result of my poor housekeeping.

As far as the range error, perhaps it has something to do with the type of node being retrieved? My experience with that first error has generally been in the context of the child list and attempts to access indexes which are undefined. Can't be sure, but it's likely that the fault error is/was related to usage of Beta 1.

  • justin

Thanks J! I upgraded to Beta

flex_vixen's picture
flex_vixen - Fri, 2007-12-14 05:35

Thanks J!

I upgraded to Beta 2 and still have the same issue exactly as described. This weekend I'm going to roll up my sleeves and start fresh... admittedly I may have overlooked something obvious in my frustration. Thanks for the help :)


Receiving the same error

45mo4s39's picture
45mo4s39 - Thu, 2008-03-27 18:37

I'm getting the same range out of error/ RPC Fault faultString="Didn't receive an acknowledge message" amfphp messages. Did you ever get this to work?


my 2 cents..

johannes - Tue, 2008-04-15 10:48

"out of range error" > probably some error in your actionscript (calling array[1].title when there is no array[1] for example..)

"Didn't receive an acknowledge message error" > sometimes appears when there is a conflict with other modules (in my case the Outline-module caused this error to appear)

Still getting same error

paulbhartzog - Wed, 2008-10-29 18:46

We are using amfphp-1.9.beta.20080120.zip and still getting this error.

/admin/logs/status shows:

Drupal 5.12
AMFPHP 1.9 Beta 2

Suggestions?

same error

johannes - Wed, 2008-10-29 19:10

hhmm..I recently got the same error and couldn't get rid of it.

This made me migrate the website to Drupal 6 where everything went perfect..

Possible solution to out of range error

dazweeja - Fri, 2009-01-23 03:50

With my installation I get this error too unless I specify which node fields I want returned. So in the above example you could change the button click event like so:

<mx:Button x="250" y="157" label="nodeLoad" click="nodeLoad()" />

And then between the Script tags add this function:

private function nodeLoad():void
{
   var nid:Number = 1; // node number
   var fields:Array = new Array();
   fields[0] = 'title';
   fields[1] = 'body'; // add required field names here
   amfService.load(nid, fields);
}

Not getting it right

hemmie - Thu, 2007-12-13 13:27

Great example, so I tried it out...
have installed:
xampp, with php version 5.2.3
drupal v 5.2

Installed and enabled the amfphp module, service module, node service
I can access them and use them through the drupal service page in adminitster

I am logged in as root on to my drupal site.

Now I tried two endpoint uri in service-config.xml:
1) "http://localhost/modules/amfphp" is where I installed my amfphp module
returns following error when I run the swf:

fault: [RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed: url: 'http://localhost/modules/amfphp'"]

???? do not what this means, anyone knows how to debug or what the problem is

2) also tried using the url which you get if click the amfphp/services link in the services (Servers, AMFPHP - /services/amfphp) page of drupal:
"http://localhost/?q=services/amfphp" as endpoint
where I get the following error:

fault: [RPC Fault faultString="Method does not exist." faultCode="AMFPHP_RUNTIME_ERROR" faultDetail="D:\work\CME\pltfrm\drupal-5.2\modules\amfphp\amfphp.module on line 101"]

where line 101 is trigger_error($message, E_USER_ERROR); in the module (which just throws the error).

I get a rather anonymous Method does not exits. Does this mean if I do node.load(1) => that the load method is not existing????

Can anybody tell me what to do and which of the two is the best approach.

Thank you.

It works

hemmie - Thu, 2007-12-13 16:45

Got it working,

one should opt for option 2.

I got my mxml source wrong.

thx

How?

johnfyoung's picture
johnfyoung - Thu, 2008-02-28 20:58

I'm missing something from your solution to this "Method does not exist" error. The app can't find a "node.load" method. You reported something wrong in your mxml source?


Ok - Duh

johnfyoung's picture
johnfyoung - Thu, 2008-02-28 21:04

I had installed the services module, amfphp module, and amfphp and enabled them in admin/build/modules...but I hadn't enabled any of the services!


Using services with Flash 9/Actionscript 3

detour's picture
detour - Thu, 2007-12-20 02:21

I'm getting started with accessing content from Drupal sites with Flash. I work with Flash 9/Actionscript 3, and I haven't yet seen any examples with it. I've had some success and wanted to share what I found.

AS3 has NetConnection and ObjectEncoding classes that support an AMF connection. I made this class to provide a simple syntax for calling Drupal services. The source for a pretty simple Flash application that retrieves the nodes from a view is here (you can see it in action here).

I've been working with Thomas Saunders (who wrote about this topic here) on this site:
http://internal.thirdavedesign.com

Also, I'm beginning to refit my own site:
http://arithmetric.com


Why directly flash ?

redben - Fri, 2008-03-28 09:17

It's just a matter of opinion but why use flash directly when you have flex libraries ? IMO with the flex framework, it is so easy and quick, and it you can add your flash content (animation or whatever) to your flex application, which is nothing but flash itself.
I still can't think of a scenario where the use of flex does not feet...I'd be pleased to have your opinion.

Just out of curiosity...

averageyoungman... - Thu, 2007-12-20 03:52

What version of PHP are you running? I tried and stumbled with this using versions of PHP < 5.

I am running 5.2.0 locally.

  • justin

help loading amfphp

sgitner - Sat, 2008-02-02 05:14

i have loaded the file exactly as you say but am experiencing some issues.

i put the update in modules/amfphp/amfphp

is that right?

i get this when I go to mysite/services/amfphp/

Forbidden

You don't have permission to access /flashdata/services/amfphp/ on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.7a mod_auth_passthrough/2.1 mod_bwlimited/1.4 PHP/4.4.8 Server at blogs.roanoke.com Port 80

please assist.

yeahhhhhaaaaaa, Great flash example, I love it

amax - Wed, 2008-02-20 12:54

Hi Guys, I finally got the flash example above with AS2, flash 8, posted by averageyoungman working. After pulling my hair out

for ages trying to figure out what was wrong, it ended up being an issue with enabling clean URLs and my htaccess file. Hours

of googling solved it, and now I can connect fine to my flash, everything is perfect, almost.

Coming from an animation background, connecting flash and drupal is my first adventure in the arena. What I would love help on

now is actually what way I should set up my flash file to take advantage of my drupal connection.

I basically have a 50 pages / nodes that I want to extract the title and body info from into dynamic text boxes on stage.

What I currently have is:

import mx.remoting.Service;
import mx.remoting.PendingCall;
import mx.rpc.RelayResponder;
import mx.rpc.FaultEvent;
import mx.rpc.ResultEvent;
import mx.remoting.debug.NetDebug;
mx.remoting.debug.NetDebug.initialize();

var node:Service = new Service("http://www.xxxxx.com/services/amfphp", new Log(), "node", null, null);

var pc:PendingCall;
function callMe(num,resultfunc){
pc = node.load(num);
pc.responder = new RelayResponder(this, resultfunc, "getData_Fault");
}

callMe(133, "getData_Result");
function getData_Result( re:ResultEvent ):Void {
mytextbox.htmlText = re.result.body;
}

callMe(134, "getData_Result2");
function getData_Result2( re2:ResultEvent ):Void {
mytextbox2.htmlText = re2.result.body;
}

If I have 50 text boxes I want to fill from Drupal content, does that mean I have to make 50 "call me" functions to populate my boxes or is there a better way I should be doing this?

No! Don't make 50 functions or 50 service calls.

averageyoungman... - Wed, 2008-02-20 20:54

The node service only accepts one node per query - or at least it did the last time I used it. You should look into the taxonomy.getTree and taxonomy.selectNodes services. getTree will allow you to select all term IDs under a vocabulary given a vocabulary ID, and selectNodes will select all the nodes from a term, or array of terms, given the term IDs you want to select from. Unless you want to write your own service, you should look into these or look for contributed services that might fit the bill. If all your nodes are in terms under one vocabulary, you should be able to use the taxonomy service and methods using one client-side service call.

Aside from that, you might want to try writing a node service that allows you to select a range of nodes based on some other criteria like uid, name, type etc.

For certain, you shouldn't write a loop that makes one query per node. You should select all the nodes you need with one query if possible.

50 nodes through views

eldude@drupal.org - Thu, 2008-02-21 07:58

if you create a view with views, you can get the 50 wanted nodes in 1 request.
( see views service )

Great!

Monica L - Tue, 2008-02-26 18:36

Thank you for showing us this, it was very interesting!

Monica, IT Freelancer currently working on the How To Get Bigger Erection project.

My latest experiments as follows

amax - Fri, 2008-03-07 15:27

Hi Guys,

As promised, my updated experiments with taxonomy below. This is working fine at present and should help any beginer like myself out who simply wants to pull in text for a banner etc. However,
I have 2 issues with various Terms I am trying to load into flash as I want to expand. My code at present is as follows:

import mx.remoting.;
import mx.rpc.
;
import mx.remoting.debug.NetDebug;
import mx.utils.Delegate;
var gatewayUrl:String = "http://www.xxxxx.com/services/amfphp";
NetDebug.initialize();
var taxonomy:Service = new Service(gatewayUrl, null, 'taxonomy', null, null);
function getContent() {
//var pc:PendingCall = taxonomy.getTree(1);
var pc:PendingCall = taxonomy.selectNodes([22], ['title', 'body']);
pc.responder = new RelayResponder(this, "handlegetContent", "handleError");
}
function handlegetContent(re:ResultEvent) {
var rs:Object = re.result;
for (var i:Number = 0; i

    //trace(i);
    _root["txt_title"+i] = rs[i].title;

    //trace(rs[i].title);
    _root["txt_body"+i] = rs[i].body;

}

}
getContent();

function getContent2() {
//var pc:PendingCall = taxonomy.getTree(1);
var pc:PendingCall = taxonomy.selectNodes([23], ['title', 'body']);
pc.responder = new RelayResponder(this, "handlegetContent2", "handleError");
}
function handlegetContent2(re:ResultEvent) {
var rs:Object = re.result;
for (var i:Number = 0; i

    //trace(i);
    _root["term2_title"+i] = rs[i].title;

    //trace(rs[i].title);
    _root["term2_body"+i] = rs[i].body;

}

}
getContent2();

Within the flash - I have simply lots of Dynamic text fields on stage with the variable lable properties box filled in as follows:
_root.txt_title7 and _root.txt_body6 etc etc depending on what number [i] refers to in my loop from drupal.

For getContent2();, my text fields properties are simply labeled as _root.term2_title7 and _root.term2_body_title7 etc etc

Issue 1 - Am I going about this the right way ? or can someone please point me in a better direction. My actionscript / programming knowledge is basic coming from a design background to Drupal. Is it ok to use functions / text box labelling like this for say 20 terms thus getContent3();, getContent4(); etc

Issue 2 - If I add a new page to drupal with one of my terms, I find I have to go back and renumber my text fields properties in flash from say _root.term2_title7 to _root.term2_title8 as each new term added seems to get numbered in Drupal as "0" up. this is killing me when I want to add something

PS I hope I am not annoying anyone with these posts but I am determined to get my head around some actionscript and drupal. I find it very interesting

you could use Charles for

g10 - Sat, 2008-03-08 18:11

you could use Charles for what you are trying to do ( http://www.xk72.com/charles/ )
this program monitors your connections, and shows the calls and the responses from your service calls in a readable way ( nicely structured objects ), which is handy to filter out the fields that you actually want ( because the objects coming from drupal can be big and contain unnecessary values )

Help me out in connecting the user.login in Services

mohamedmustaf - Wed, 2008-03-12 11:31

Hi I need a sample how to use the service for user login and log out since i am using flex as frontend. I have conected the database and worked out with the smpale but i am able to login even if i provide a wrong username and password. Please help me out how to use the user service in amfphp.

You are able to login with a

redben - Fri, 2008-03-28 09:21

You are able to login with a wrong username and password ? how ? can you explain more and/or post your flex code ?

Same issue

leoman_730@drup... - Thu, 2008-08-14 20:09

I encountered the same issue for user.login.
It should be very easy to re-create the problem
Just create a simple login form in flex, and then call the user.login("username","password"). Ok, i can connect to the remote server and play as normal. Then I close the program, and enter ramdon user name and password, bingo...
I am able to login.

I think the issue is with the session. Once user.login() call is success, it create a session and that session never expire. Why i say that? because after i clean up all the session and cookies from my browser, and i try login using ramdon name, it throw me an authentication error.

I have tried using user.logout(), but that didnt work.

Any idea would be great. Thanks.

autologout

freddymx's picture
freddymx - Thu, 2008-08-14 21:37

I'm using automatic logout module => http://drupal.org/project/autologout ... using user.logout worked for me sometimes

FREDDY


What do you mean by

ven@drupal.org - Sat, 2009-03-07 23:25

What do you mean by "sometimes"?

I can't get user.logout() to work either. I am not using autologout, though I will eventually. But for now i would prefer this simple function to work, seems like I'm not getting something here.

Weird thing is that user.logout() just silently fails. I do not get showBusyCursor or any fault/result event at all. All other functions I have tested so far works as a charm.

[Edit]

Problem was Flex. See http://drupal.org/node/178051

Have to use user.getOperation('logout').send() instead.

Data Grid Data

ryosaeba - Fri, 2008-06-20 11:07

Dear Drupal Friends

I've try to make a mxml application in FLEX that read by AMFPHP a nodes

Well my mxml code is:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script source="main.as" />
<mx:RemoteObject showBusyCursor="true" destination="amfphp" sorce="views" id="views">
   <mx:method name="getView" result="onViewsResult(event)" fault="onFault(event)" />
</mx:RemoteObject>
<mx:Panel width="500" height="400" layout="absolute" title="Recipes" horizontalCenter="0" verticalCenter="0">
        <mx:DataGrid x="10" y="10" width="460" height="204" id="recipes_select" dataProvider="{recipes}" >
           <mx:columns>
             <mx:DataGridColumn headerText="NID" dataField="nid" width="40"/>
               <mx:DataGridColumn headerText="Dish" dataField="title"/>
         </mx:columns>
        </mx:DataGrid>
       <mx:Label x="10" y="222" text="Dish"/>
     <mx:TextInput x="10" y="241" width="460" id="dish"/>
     <mx:Label x="10" y="278" text="Recipe"/>
       <mx:TextArea x="10" y="294" width="460" height="56" id="recipe"/>
      <mx:Button x="416" y="267" label="Save"/>
      <mx:Button x="420" y="217" label="New"/>
   </mx:Panel>
 
</mx:Application>

And my Actionscript code is:

// ActionScript file
import mx.controls.;
import mx.rpc.events.
;
import mx.rpc.remoting.*;
import mx.utils.ArrayUtil;
import mx.events.ResizeEvent;



[Bindable]
public var recipes:Array;

public function init():void
{
getRecipes();
}

public function onFault(event:FaultEvent):void
{
  Alert.show(event.fault.faultString, "Error");
}

public function onViewsResult(event:ResultEvent):void
{
recipes = ArrayUtil.toArray(event.result);
}

public function getRecipes():void
{
  views.getView("recipes_all", ['nid','title','body','changed']);
}

Well... If I try to run the application i see this error:

http://www.walterfantauzzi.com/forum/drupal_flex/img_f_d.jpg

I can't understand why I've this error...

Someone can help me please?

I noticed

behindthepage's picture
behindthepage - Sat, 2008-06-21 04:15

ryosaeba

4th line in MXML code has a smelling pistake.
sorce="views"

<mx:RemoteObject showBusyCursor="true" destination="amfphp" sorce="views" id="views">

Regards
Geoff


Hi ryosaeba, I'm a noob as

david.d.patrick - Fri, 2008-06-20 15:45

Hi ryosaeba,

I'm a noob as well, still I can offer a few comments about getting this Flex / Drupal to work.

  1. Have you checked your service through Drupal (Admin -> Build -> Services) and checked your settings to make sure use keys, strict domain checking and use sessid are unchecked.

    1. Have you tried the service out by clicking it to see if you can add and or delete a node or (recipe) only in Drupal. You've got to make sure Drupal back end works first before you try it Flex/ Flash, or you'll get runtime errors.
  2. If you can include a copy of the service you're using it would be a great help, so I can recreate the issue on my end to help better figure this out.

                         ****Also I like your web site intro , pretty freakin sweet!*****
    

    Drupal and Flex yeah!!!!

Services + AMFPHP vs. AMFPHP

lambeco - Tue, 2008-09-23 20:58

I'm trying to get this to work with Flash/AS3 and I'm having a little difficulty. Here is the AS3 code I'm using:

package {
    import flash.display.Sprite;
    import flash.net.Responder;
  
    import RemotingConnection;
   
    public class Document extends Sprite {
        public var dataProvider:Array;
        public var gateway:RemotingConnection;
     
        public function Document() {
            this.init();
        }
      
        public function init() {
            /This works, but doesn't give me access to Drupal data/
            //var gatewayUrl:String = "http://XXXXXX.COM/DRUPAL_SUBDIR/modules/amfphp/amfphp/gateway.php";

            /This doesn't work/
            var gatewayUrl:String = "http://XXXXXX.COM/DRUPAL_SUBDIR/services/amfphp";

            gateway = new RemotingConnection(gatewayUrl);
            var responder:Responder = new Responder(onResult, onFault);
            var arg:String = 'foo';
            gateway.call( "HelloWorld.say", responder, arg);
        }
      
        public function onResult(result):void {
            trace('onResult invoked');
            trace(result);
        }
    
        public function onFault(error:Object):void {
            for each(var node in error) {
                trace(node);
            }
        }
    }
}

This is what gets traced out when the whole thing goes south:

Method <em>HelloWorld.say</em> does not exist.
101
User Error
/WEBROOT/domains/XXXXXX.COM/html/DRUPAL_SUBDIR/modules/amfphp/amfphp.module
AMFPHP_RUNTIME_ERROR

However, when I access the gateway directly (the first gatewayUrl), it returns:

onResult invoked
You said: foo

I sorta figured that maybe the AMFPHP module maintains its own services and doesn't repeat the services in the /modules/amfphp/amfphp/services directory, but the AMFPHP browser doesn't work using "http://domain.com/drupal_subdirectory/services/amfphp" either (though it works with a direct URL to gateway.php), throwing this error:

(mx.rpc::Fault)#0
  errorID = 0
  faultCode = "AMFPHP_RUNTIME_ERROR"
  faultDetail = "/WEBROOT/domains/XXXXXX.COM/html/DRUPAL_SUBDIR/modules/amfphp/amfphp.module on line 101"
  faultString = "Method <em>DiscoveryService.getServices</em> does not exist."
  message = "faultCode:AMFPHP_RUNTIME_ERROR faultString:'Method <em>DiscoveryService.getServices</em> does not exist.' faultDetail:'/WEBROOT/domains/XXXXXX.COM/html/DRUPAL_SUBDIR/modules/amfphp/amfphp.module on line 101'"
  name = "Error"
  rootCause = (null)

Sorry for the wall of text, but this is driving me insane, and I'm having a really hard time finding information that could help me with this. There don't seem to be any comprehensive tutorials. I'm planning on writing one, start to finish (for people like me who are new to Drupal) once I have this sorted!

Thanks!

Hi lambeco, firstly, the

vannen - Wed, 2008-09-24 10:45

Hi lambeco,

firstly, the URL

http://XXXXXX.COM/DRUPAL_SUBDIR/services/amfphp

is the one you want to use to connect to the services module. It definitely should work as I've been using it!

You're trying to call helloworld.say, which I'm assuming is the Hello World example that comes with AMFPHP? if so, the URL you need to connect to the Hello World example service is

var gatewayUrl:String = "http://XXXXXX.COM/DRUPAL_SUBDIR/modules/amfphp/amfphp/gateway.php";

So what's happening is this (by the sound of it) - you're connecting to the hello world example just fine. But you're then trying to get Drupal data out of helloworld, which it isn't set up for. Helloworld is just a simple few lines of code that echoes back to you.

What you need to do is to go into your modules, enable services (really?! ;-) ) services-servers-AMFPHP, and, say, the node service or views service.

Then, the gateway you use is:

http://XXXXXX.COM/DRUPAL_SUBDIR/services/amfphp

And, instead of calling helloworld (which you can't access from this gateway), you call the node or view service.

In my code I use:

connection.call("views.getView", responder, viewName, arrayOfArgs);

Where views.getview is the service. It gets a view that I've specified as a string var viewName, with an array of arguments. The arguments are optional, so maybe leave them out 'til you've got the connection running?

Hope that helps, feel free to ask for more assistance!

DV

That did it!

lambeco - Thu, 2008-09-25 21:24

Thanks so much, vannen! That worked.

For those stuck like me, my gateway call now looks like this (make sure you actually have a node to load):

var responder:Responder = new Responder(onResult, onFault);
var arg:int = 1;
gateway.call( "node.load", responder, arg);

Can someone just post a

superjames@drup... - Tue, 2008-10-14 22:05

Can someone just post a simple way to authenticate a Flex app using automatic login and API key? I want to use Air so it needs to automatically log in and have the ability to retrieve and create nodes. This sure is hard information to find!
Thanks

Not working

rwsprashant's picture
rwsprashant - Thu, 2008-12-25 09:00

hey I am using the same steps but not getting the proper result
I am getting the following error .. Please help me
fault: [RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed: url: 'http://suse/websites/rightway/work/greg/vitaplanner/drupal5/services/amfphp'"]


Gateway

seppestaes - Fri, 2009-03-13 18:06

AMFPHP 1.9 needs to be installed in the 'amfphp' folder within your drupal installation.
The path to the gateway will be something like

"{server}/suse/websites/rightway/work/greg/vitaplanner/drupal5/services/amfphp/amfphp/gateway.php"

(see three posts up, vannen)

Very stupid question

aikiken - Thu, 2009-03-05 00:22

Would it be too hard for someone to take me by the hand and tell me how to actually use the resulting mxml file in drupal? I can't seem to find this info here or anywhere but you all seem to know... Please... :)

re

aholetec's picture
aholetec - Thu, 2009-03-05 18:01

You don't use the flex MXML file in drupal, but you compile the code and upload the swf file to drupal.
The swf file is located under the bin folder from your Flex Project.
In order to do the upload you can use Flash Node module for that. http://drupal.org/project/flashnode
Hope this answers your question.


failed to retrieve node

babymission - Fri, 2009-05-01 01:56

I am running drupal 6.x in the Localhost (in Linux) for a while, everything is working ok so I tried to connect the flex application in drupal

I previously installed the Dashplayer so I already get the services, amfphp, views, etc working according to the instructions, and the Dashplayer is working fine.

In the user permission, I already check the permissions (for both annoymous and authenticated users) for all necessary access such as access content, load any node data, load own node data, access services, upload files, view upload file, access all views.

The service browser is also working fine, but I need to put the exact path "http://localhost/drupal/modules/amfphp/amfphp/broswer/index.html" in order to access to the browser screen. The link "Load the service browser" given in the service module does not work for me.

Then I compiled the flex project in Windows using flex builder, according to the instruction given here, and then I copied the swf file in the bin-release folder, and then go to drupal in my linux localhost to create a node, and attach this swf file to the node. I then double click the swf file drectly in the node. It shows up the interface page. But when I click the nodeLoad button, it did not return any anything, but keep showing the message "Transferring data from localhost...." at the status bar at the bottom and nothing really happened. I also checked the crossdomain.xml file (I put it in /var/www/drupal)to make sure it allows the localhost.

The endpoint uri I assigned in the services-config.xml file is "http://localhost/drupal/services/amfphp"

I also try many different endpoint uri (e.. use the actual path, with gateway.php, put localhost:80, et),but it is still does not work.

In the service settings, I already unchecked the User key and User Sessid.

I read some posts saying we need to put the drupal user login in the flex? but it was also said that as long as we check all the required user permission in drupal, it should be fine.

Can anyone give me some hints and helping hand to me as I have been working many weeks already and still did not get flex connected to drupal. Thanks.

Clean URL's enabled?

seppestaes - Fri, 2009-05-01 07:53

Already mentioned in one of the posts above, so just to check: do you have clean URL's enabled?
If not, you could maybe try something like:

http://localhost/drupal/?q=services/amfphp

in your services-config.xml

or enable clean URL's

yes, I already enabled the

babymission - Sat, 2009-05-02 00:36

yes, I already enabled the URL's, but it is not working.