Advertisement

02.14.2008 at 10:06AM PST, ID: 23163783
[x]
Attachment Details
[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!

9.2

Actionscript 3 Flash CS3 data providers

Asked by glhelinski in Macromedia Flash, Miscellaneous Programming, Adobe Creative Suite

Tags: , , ,

Hello,

I'm trying to learn Flash CS3 and Actionscript all at one shot.  There are very good examples at the url listed below but lots of them have steps like these 3 below.  I guess I know how to do 1 (add the labels, buttons, etc).  #2 I can figure out I think BUT... #3 set the document class in the FLA file to DataProviderExample.  I have no idea what this means and I cannot find any clues anywhere.
I'm clueless:-)

I think my steps would be to go into Flash, create an FLA and make the labels and buttons myself and name the instances of each.
Then for each components I place on the stage, comment out where they are declared below such as:

"//var description:Label = new Label();"
etc

But what does #3 mean?

Am I beyond help?

Thanks...the url is below.
see code snippet

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/data/DataProvider.html#getItemAt()

Start Free Trial
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:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
//This example demonstrates how data providers can be used to maintain the contents of several data grids. 
//To run the example, follow these steps:
 
//1 Add the Label, Button, ComboBox, TextInput, and DataGrid components to the library. 
//2 Save this code as DataProviderExample.as in the same directory as your FLA file. 
//3 Set the Document class in the FLA file to DataProviderExample. 
 
 
package
{
    import fl.controls.Button;
    import fl.controls.ComboBox;
    import fl.controls.DataGrid;
    import fl.controls.Label;
    import fl.controls.TextInput;
    import fl.data.DataProvider;
    import flash.display.Sprite;
    import flash.events.*;
    import flash.text.TextFieldAutoSize;
    
    public class DataProviderExample extends Sprite
    {        
        private var southern:DataGrid;
        private var northern:DataGrid;
        private var world:DataGrid;
        private var southernRoster:DataProvider;
        private var northernRoster:DataProvider;
        private var leagueCB:ComboBox;
        private var nameTI:TextInput;
        private var goalsTI:TextInput;
        private var submitBtn:Button;
 
        public function DataProviderExample() {
            southernRoster = new DataProvider();
            northernRoster = new DataProvider();
            
            createDataGrids();
            createUI();
        }
 
        private function createUI():void {
            var description:Label = new Label();
            description.text = "Enter player's name, goals scored, and hemisphere of origin:";
            description.autoSize = TextFieldAutoSize.LEFT;
            nameTI = new TextInput();
            goalsTI = new TextInput();
            
            var submitBtn:Button = new Button();
            submitBtn.label = "Submit Player";
            submitBtn.addEventListener(MouseEvent.CLICK, submitPlayer);
            
            leagueCB = new ComboBox();
            leagueCB.addItem( { label:"Northern", data: 0 } );
            leagueCB.addItem( { label:"Southern", data: 1 } );
            
            description.move(10,10);
            nameTI.move(10,40);
            nameTI.setSize(150,24);
            goalsTI.move(170,40);
            goalsTI.setSize(40,24);
            leagueCB.move(220,40);
            leagueCB.setSize(120,24);
            submitBtn.move(350,40);
            goalsTI.restrict = "0123456789";
            
            addChild(description);
            addChild(leagueCB);
            addChild(submitBtn);
            addChild(nameTI);
            addChild(goalsTI);
        }
        private function submitPlayer(e:MouseEvent):void {
            if(nameTI.text != "" && goalsTI.text != "") {
                var targetRoster:DataProvider;
 
                if(leagueCB.selectedItem.label == "Southern") {
                    targetRoster = southernRoster;
                }
                else {
                    targetRoster = northernRoster;
                }
    
                targetRoster.addItem( { Name: nameTI.text, Goals: goalsTI.text } );
                
                var worldRoster:DataProvider = southernRoster.clone();
                worldRoster.merge(northernRoster);
                worldRoster.sortOn("Goals", Array.NUMERIC | Array.DESCENDING);
                southernRoster.sortOn("Goals", Array.NUMERIC | Array.DESCENDING);
                northernRoster.sortOn("Goals", Array.NUMERIC | Array.DESCENDING);
                
                world.dataProvider = worldRoster;
                
                nameTI.text = "";
                goalsTI.text = "";
            }
        }        
 
        private function createDataGrids():void {
            southern = new DataGrid();
            northern = new DataGrid();
            world = new DataGrid();
            southern.move(10,100);
            northern.move(180,100);
            world.move(350,100);
            southern.setSize(170, 250);
            northern.setSize(170, 250);
            world.setSize(170, 250);
            southern.columns = 
            northern.columns = 
            world.columns = [ "Name", "Goals" ];
            southern.dataProvider = southernRoster;
            northern.dataProvider = northernRoster;            
            addChild(southern);
            addChild(northern);
            addChild(world);
 
            var northernLabel:Label = new Label();
            northernLabel.autoSize = TextFieldAutoSize.LEFT;
            northernLabel.text = "Southern Hemisphere";
            northernLabel.move(10,75);
            addChild(northernLabel);
            var southernLabel:Label = new Label();
            southernLabel.autoSize = TextFieldAutoSize.LEFT;
            southernLabel.text = "Northern Hemisphere";
            southernLabel.move(180,75);
            addChild(southernLabel);
            var majorLabel:Label = new Label();
            majorLabel.autoSize = TextFieldAutoSize.LEFT;
            majorLabel.text = "World";
            majorLabel.move(350,75);
            addChild(majorLabel);
        }
    }
}
[+][-]02.18.2008 at 03:59AM PST, ID: 20919142

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Macromedia Flash, Miscellaneous Programming, Adobe Creative Suite
Tags: Adobe, Flash, CS3, using Actionscript 3.0
Sign Up Now!
Solution Provided By: blue-genie
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628