Do not use on any
shared computer
September 5, 2008 05:26am pdt
 
[x]
Attachment Details

Array of objects created inside cgi call onload,  and passing to a function: need help to make it work

Tags: Adobe, Flash 8 Pro, 8 Pro, actionscript 2.0
Ok this isn't easy to describe but here goes.

This Flash Pro 8 a.s. 2.0 program prompts the user for 2 values and once a submit button is clicked it calls a program on a UNIX server:

lVars.sendAndLoad("http://...url.../pgm_on_unix_server", lReceiver, "POST");

it extracts data, manipulates it, and sends results back. The onload function sits and waits for it to return

lReceiver.onLoad = function(   ) {

 data returned is then graphed and tabulated(datagrid) .

Now my problem is that I create an array of objects inside the section of code under the lReceiver.onload and then I want to access it inside another function and can't seem to get it right. It just won't see it.

It is probably some form of scope problem, but it isn't an area I excel in.

If something is created inside the onload how should I access it in a separate function?

Attached hopefully is some heavily edited code (thousands of other lines of code removed, so may miss important info)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
//===============================================================
main 
//===============================================================
import submitButton.as
import cgiCode.as
import processATable.as
 
 
lReceiver.onLoad = function(...stuff...) {
 
	if (_global.cgiSuccess == 1) {
 
		var aTable = new Array();
 
		// loop and create an array of objects
 
		for (i=0; i<=6; i++) {
			//use a temporary object
			var myObj = new Object();
			// 
			myObj[blah] = this[blahblah];
			aTable[i] = myObj;
			delete myObj;
		}
 
		// call the processATable () code function
 
		processATable( ..stuff..);
 
	} else {
		// error sending i.e. success not equal to "1"
		trace("error!");
	}
};
//===============================================================
cgiCode.as:
//===============================================================
var nowRunPgm = function ( ... ) {
// essentially after a couple of lat lon values are entered by the user
// it calls a UNIX program to extract some data , some number cruching happens
// and it gets passed back to flash
//
	_global.cgiSuccess = 0;
	_level0.success = null;
	lVars.sendAndLoad("http://...url.../pgm_on_unix_server", lReceiver, "POST");
 
};
//===============================================================
submitButton.as
//===============================================================
....function
{
//code which waits for submit button in a form containing data which calls the nowRunPgm();
//just button press event listeners here which invoke the UNIX call
// after a user enters values required
 
 
...
 
}
//===============================================================
processAtable.as
//===============================================================
.... function ( ...) {
 
// i want to access aTable in here but can't
 
// not accessible as _root.aTable
// can't work out how to pass it from inside the lreceiver.onload to inside here
 
 trace(_root.aTable) >> undefined
 
//have tried passing it through arguments and no success either 
 
}
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Web Development
Question Asked By: madmax61
Solution Provided By: adler77
Participating Experts: 1
Solution Grade: B
Views: 0
Translate:
Loading Advertisement...
 
[+][-]Accepted Solution by adler77
Accepted Solution by adler77:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by madmax61
Author Comment by madmax61:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by madmax61
Author Comment by madmax61:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by madmax61
Author Comment by madmax61:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Open Discussion
Open Discussion
 
Comment by madmax61
After accepting this solution I set about continuing my program happy to continue with using a globally declared variable. However I found I couldn't access the global variable either in the same way I was trying to access the local variable.

Well here is the problem:

To access a single "table" entry I had to do:

trace( aTable[3]["A"] );

or trace( aTable[3].A );

However I was using round brackets such as:  trace( aTable(3)["A"] );

SO I can now access the local variable even inside a function, and even without passing it as an argument, which is more expected behaviour in flash environment.

Given the code segments from my original question (as I said it was heavily edited), you couldn't have picked up the error.

Cheers,
Max

 
 
20080723-EE-VQP-34 / EE_QW_2_20070628