Hi
I have to show many text+image article in flash, like a "news section" that have the news article with the corrispondent image.
How can i do this with the amfphp.module?

I think about load the stories with get.view but how to load the correspond images, with cck?
The publisher that wrote the story trough drupal should attach the images in the story?
And how to order, from new to old the article loaded?

Thanks in advance

Fever

Comments

newms’s picture

You are going to have to write your own custom service to do this. Have you read the Services handbook?

fever’s picture

Yes but i don't undestand clearly what i have to do..

newms’s picture

Have you watched the screen casts? They were particularly helpful for me in understanding what was going on. I'm asking because it's pretty complex and I think Scott does a great job of explaining the concepts behind everything - a better job than I could do IMO, but if there is something specific about writing your service module that you don't understand then I can help you.

funkyboy’s picture

...with attention.
In the screencast the retrieval works because, before running the swf in the browser, you log in as admin.
My question is: can it work differently.
Can I allow someone else (possibly) anonymous to watch the recipe I uploaded?

My goal is to develop an app where the admin posts content (text, pics) and people (not admin) watch them.

thanks,

-c.

funkyboy’s picture

I noticed that I create new recipes on the client side with flash, but they don't show up in my recent posts. shouldn't they appear also there?

funkyboy’s picture

discovered right now that they are not published...sorry.

anyway the problem of accessing data with no previous login to me is crucial.

thanks in advance for any help you can provide.

newms’s picture

Hi,

Just give anonymous users the right to access services under adminster>user management>access control.

Hope that helps.

horizens’s picture

We have never had to write our own Service though. The bundled services that Scott Nelson wrote suit our needs just fine.

The approach that we've taken to tackle this problem is to use a combination of CCK (http://drupal.org/project/cck), Views (http://drupal.org/project/views), Imagefield (http://drupal.org/project/imagefield), and Amfphp/Services (http://drupal.org/project/amfphp | http://drupal.org/project/services). Be sure to follow the amfphp installation instructions with regard to installing amfphp 1.9.

We use clean urls, so this example also assumes that you have enabled them as well.

After installing all of the modules listed above, enable all of them in Administer/Site Building/Modules. Also enable Node Service and Views Service.

Then go to Administration/User Management/Access Control and enable "access services" for anonymous users. In Administer/Site Building/Services, turn off API key and Session Key.

Now create a new Content Type under Administer/Content Management/Content Types. For this example, the News Content Type will contain Title, Image, and Body fields. I've exported the the code for this example that you can load in if you are using Contemplate (http://drupal.org/project/contemplate).

$content[type]  = array (
  'name' => 'News',
  'type' => 'news',
  'description' => '',
  'title_label' => 'Title',
  'body_label' => 'Body',
  'min_word_count' => '0',
  'help' => '',
  'node_options' => 
  array (
    'status' => true,
    'promote' => false,
    'sticky' => false,
    'revision' => false,
    'moderate' => false,
  ),
  'comment' => '0',
  'old_type' => 'news',
  'orig_type' => '',
  'module' => 'node',
  'custom' => '1',
  'modified' => '1',
  'locked' => '0',
);
$content[fields]  = array (
  0 => 
  array (
    'widget_type' => 'image',
    'label' => 'news_image',
    'weight' => '0',
    'max_resolution' => 0,
    'image_path' => '',
    'custom_alt' => 0,
    'custom_title' => 0,
    'description' => '',
    'field_news_image_upload' => '',
    'upload' => 'Upload',
    'default_value_php' => '',
    'required' => '1',
    'multiple' => NULL,
    'field_name' => 'field_news_image',
    'field_type' => 'image',
    'module' => 'imagefield',
    'default_value' => NULL,
  ),
);

Next, create a new view to load each news items into. I've called mine News just to keep things simple. Again, I've exported sample settings that you can import into the News view in order for this to work.

  $view = new stdClass();
  $view->name = 'news';
  $view->description = '';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = 'News';
  $view->page_header = '';
  $view->page_header_format = '1';
  $view->page_footer = '';
  $view->page_footer_format = '1';
  $view->page_empty = '';
  $view->page_empty_format = '1';
  $view->page_type = 'teaser';
  $view->url = 'news';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '10';
  $view->menu = TRUE;
  $view->menu_title = 'News';
  $view->menu_tab = FALSE;
  $view->menu_tab_default = FALSE;
  $view->menu_tab_weight = '0';
  $view->sort = array (
  );
  $view->argument = array (
  );
  $view->field = array (
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => 'news',
),
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node);
  $views[$view->name] = $view;

Save the view.

Now, in your menu select News under the Create Content link. Give the news item a title, upload an image, add the body, and save it. If you used the code above to import the News View, you should have a menu item called News. If you click there you should see your first news item posted there. We're half way done.

You can test the views.getView Service in the Services browser under Administer/Site Building/Services. In the view_name field, use the name that you gave your view. If you imported my view settings above, you would use news. When you click Call Method, it should return your news item. If it did, let's move on to the Flash side of this example.

Create a new Flash file and paste this code into the first frame:

	// Import the remoting classes

	import mx.remoting.*;
	import mx.rpc.*;
	import mx.utils.Delegate;
	import mx.remoting.debug.NetDebug;

	// Create variables for the gateway and site root. The site root is necessary for the image paths.

	var gatewayUrl:String = "http://localhost/drupal/services/amfphp";
	var siteRoot:String = "http://localhost/drupal/";

	// Create Service variables

	var view:Service = new Service (gatewayUrl, null, 'views', null, null);
	var node:Service = new Service (gatewayUrl, null, 'node', null, null);

	NetDebug.initialize ();

	// Call the getView function and pass it the view name and the callback function

	getView ("news","buildNews");

	// Callback function

	function buildNews (re:ResultEvent)
	{
		// Create a variable to store the results

		var oNews:Object = re.result;

		// Create empty TextFields and an empty MovieClip to load the news item into

		var nTitle_txt:TextField = this.createTextField ("nTitle_txt", this.getNextHighestDepth (), 50, 50, 200, 30);
		var nBody_txt:TextField = this.createTextField ("nBody_txt", this.getNextHighestDepth (), 50, 80, 200, 200);
		var nImage_mc:MovieClip = this.createEmptyMovieClip ("image_mc", this.getNextHighestDepth ());

		// Create a MovieClipLoader and Listener

		var mcl:MovieClipLoader = new MovieClipLoader ();
		var oListener:Object = new Object ();
		mcl.addListener (oListener);

		// Set attributes for the TextFields and MovieClip

		nTitle_txt.html = true;
		nBody_txt.html = true;
		nBody_txt.multiline = true;
		nBody_txt.wordWrap = true;
		nImage_mc._x = 300;
		nImage_mc._y = 20;

		// Populate the TextFields with the loaded content

		nTitle_txt.htmlText = oNews[0].title;
		nBody_txt.htmlText = oNews[0].body;

		// Create event listeners

		oListener.onLoadProgress = function (target_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void 
		{
			trace (target + ".onLoadProgress with " + bytesLoaded + " bytes of " + bytesTotal);
		};
		oListener.onLoadInit = function (target_mc:MovieClip)
		{
			trace (target_mc + ".onLoadInit");
		};

		// Populate the MovieClip with the loaded content

		mcl.loadClip (siteRoot + oNews[0].field_news_image[0].filepath,nImage_mc);
	}

	// The amfphp functions

	function getView (viewName:String, handler:String, fields:Array, arg:Array)
	{
		var pc:PendingCall = view.getView (viewName, fields, arg);
		pc.responder = new RelayResponder (this, handler, "handleRemotingError");
	}

	function getNode (nodeID:Number, handler:String)
	{
		var pc:PendingCall = node.load (nodeID);
		pc.responder = new RelayResponder (this, handler, "handleRemotingError");
	}

	function handleRemotingError (fault:FaultEvent):Void
	{
		NetDebug.trace ({level:"None", message:"Error: " + fault.fault.faultstring});
	}
	

Test the movie and your first news item should load into Flash.

fever’s picture

Thanks

fever’s picture

$content[type] = array (
'name' => 'News',
'type' => 'news',
'description' => '',
'title_label' => 'Title',
'body_label' => 'Body',
'min_word_count' => '0',
'help' => '',
'node_options' =>
array ( .........................................

Where i have to load this content? i have tried in the body and teaser, but when i post a news content with an image, this is show like ascii code and not like an image.
Title and description works, but image not.

>> In the view_name field, use the name that you gave your view. If you imported my view settings above, you would use news. When you >> click Call Method, it should return your news item. If it did, let's move on to the Flash side of this example.

In the service module i don'ts see "news" and than the flash file don't work.
Amfphp,clean url's and all the primary setting are ok.
Why?

Thanks

horizens’s picture

You have to use contemplate to load that code.

Or

1. Create a new content type under Admin/Content management/Content types
2. Name:* "News"
3. Type:* "news"
4. Save it
5. Edit it
6. Add field
7. Give the field a name of "news_image"
8. Select Image for the Field Type
9. Save it