473,324 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Named functions with return values

69
Hi,

I would like to change the following anonymous to a named function which receives the newsID as an argument and returns the title, content and image of the article (which are currently done within the function).

Expand|Select|Wrap|Line Numbers
  1. titleMC.onRelease = function()
  2. {
  3.     varSenderContent = new LoadVars();
  4.     varReceiverContent = new LoadVars();
  5.     varSenderContent.newsID = this.newsID;
  6.     varSenderContent.sendAndLoad("localhost/GetNewsDetail.php", 
  7.          varReceiverContent, "GET");
  8.     varReceiverContent.onLoad = function() 
  9.     {
  10.          for (p in this) 
  11.          {
  12.               if (typeof this[p] == "string") 
  13.               {
  14.      articleContent = this.data.split('~');
  15.      _root.copy_mc.article.text = articleContent[1];
  16.      image = "http://www.bemod.co.uk/images/newsImages/" + 
  17.                        articleContent[2];
  18.                                 var CTNR_WIDTH=525; //original width of container            var CTNR_HEIGHT=156; //original height of container
  19.                                 loadMovie(image, "_root.photo_mc"); 
  20.                                 _root.photo_mc._xscale=CTNR_WIDTH/800*100;                            _root.photo_mc._yscale=CTNR_HEIGHT/600*100;
  21.                                 _root.title_mc.title.text = articleContent[0];
  22.             }
  23.         }
  24.     }
  25. }
  26.  
For calling the function I think I use the following syntax, once it's been given a name,
Expand|Select|Wrap|Line Numbers
  1. titleMC.onRelease = returnArticleContent( newsID )
but how do I retrieve the values that I returned from the function?

Thanks,

Sean
Aug 30 '07 #1
3 3883
xNephilimx
213 Expert 100+
Hi, you cannot make a function return multiple values, what you can do is make the function do all by itself without returning anything, or returnan array or an object and use that returned array/object to do whatever you whant.
Anyway, you cannot call a function that return values the way you did, that way the button will recieve the returned "something". You need to call the function from a variable, so the variable will be the one recieving what the function returns. Like this:
Expand|Select|Wrap|Line Numbers
  1. titleMC.onRelease = function() {
  2.      //if the function returns an array:
  3.      var some:Array = returnArticleContent; //yes, if you dont pass parameters, you don't put ();
  4.     //if the function returns an object:
  5.      var some:Object = returnArticleContent;
  6.  
  7.      //now do whatever you want with the "some" variable.
  8. }
  9.  
If the function returns an object, the variable will become that object. And then you can work with that variable -now an object- and do whatever you want width it.

Kind regards,
The_Nephilim

PD: Sorry if I missed any "k", I'm not in my house and this eyboard sucs

Hi,

I would like to change the following anonymous to a named function which receives the newsID as an argument and returns the title, content and image of the article (which are currently done within the function).

Expand|Select|Wrap|Line Numbers
  1. titleMC.onRelease = function()
  2. {
  3.     varSenderContent = new LoadVars();
  4.     varReceiverContent = new LoadVars();
  5.     varSenderContent.newsID = this.newsID;
  6.     varSenderContent.sendAndLoad("localhost/GetNewsDetail.php", 
  7.          varReceiverContent, "GET");
  8.     varReceiverContent.onLoad = function() 
  9.     {
  10.          for (p in this) 
  11.          {
  12.               if (typeof this[p] == "string") 
  13.               {
  14.      articleContent = this.data.split('~');
  15.      _root.copy_mc.article.text = articleContent[1];
  16.      image = "http://www.bemod.co.uk/images/newsImages/" + 
  17.                        articleContent[2];
  18.                                 var CTNR_WIDTH=525; //original width of container            var CTNR_HEIGHT=156; //original height of container
  19.                                 loadMovie(image, "_root.photo_mc"); 
  20.                                 _root.photo_mc._xscale=CTNR_WIDTH/800*100;                            _root.photo_mc._yscale=CTNR_HEIGHT/600*100;
  21.                                 _root.title_mc.title.text = articleContent[0];
  22.             }
  23.         }
  24.     }
  25. }
  26.  
For calling the function I think I use the following syntax, once it's been given a name,
Expand|Select|Wrap|Line Numbers
  1. titleMC.onRelease = returnArticleContent( newsID )
but how do I retrieve the values that I returned from the function?

Thanks,

Sean
Aug 31 '07 #2
Sebarry
69
Thanks so much. That's perfect. You star!!!!

Hi, you cannot make a function return multiple values, what you can do is make the function do all by itself without returning anything, or returnan array or an object and use that returned array/object to do whatever you whant.
Anyway, you cannot call a function that return values the way you did, that way the button will recieve the returned "something". You need to call the function from a variable, so the variable will be the one recieving what the function returns. Like this:
Expand|Select|Wrap|Line Numbers
  1. titleMC.onRelease = function() {
  2.      //if the function returns an array:
  3.      var some:Array = returnArticleContent; //yes, if you dont pass parameters, you don't put ();
  4.     //if the function returns an object:
  5.      var some:Object = returnArticleContent;
  6.  
  7.      //now do whatever you want with the "some" variable.
  8. }
  9.  
If the function returns an object, the variable will become that object. And then you can work with that variable -now an object- and do whatever you want width it.

Kind regards,
The_Nephilim

PD: Sorry if I missed any "k", I'm not in my house and this eyboard sucs
Sep 1 '07 #3
xNephilimx
213 Expert 100+
You're welcome Sebarry.
Good luck with your project.

Best regards!
The_Nephilim

Thanks so much. That's perfect. You star!!!!
Sep 2 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: BlueDragon | last post by:
The place where I work is moving to MS SQL Server from Lotus Notes. I have done a lot of coding in Lotus Notes, and have, I suppose, intermediate skills in basic SQL -- queries, insert, updates,...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
6
by: Danny Lesandrini | last post by:
I'm using an Access database to drive a web site and the colors of various table backgrounds are stored in Access. I want users of the Access database to be able to select colors for the site, but...
14
by: Kejpa | last post by:
Hi, I have a function Sum as.... Function Sum(ByVal ParamArray Values() As Double) As Double Dim rSum, itm As Double For Each itm In Values rSum += itm Next Return rSum End Function
2
by: Ben Voigt | last post by:
I have a function that is called for several distinct reasons. It is conceivable that a subclass would want to handle those cases differently. Therefore, what I want to do is have multiple v-table...
14
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To...
36
by: Pacific Fox | last post by:
Hi all, haven't posted to this group before, but got an issue I can't work out... and hoping to get some help here ;-) I've got a base object that works fine with named arguments when called...
1
MMcCarthy
by: MMcCarthy | last post by:
Access has a number of built-in functions which can be generally used in queries or VBA code. Some of the more common ones are: Note: anything in square brackets is optional Date Functions ...
9
by: Gabriel Rossetti | last post by:
Hello, I can't get getattr() to return nested functions, I tried this : .... def titi(): .... pass .... f = getattr(toto, "titi") .... print str(f) .... Traceback...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.