~ubuntu-branches/debian/squeeze/pygments/squeeze

« back to all changes in this revision

Viewing changes to tests/examplefiles/as3_test.as

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ożarowski
  • Date: 2009-09-13 10:13:17 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090913101317-2w7g3lf43pginyc7
Tags: 1.1.1+dfsg-1
* New upstream release
  - upstream tarball repackaged: tests/examplefiles removed (at least one
    of example files is not DFSG-free and I'm too lazy to review the rest
    as most of them have different copyright holder and license),
    get-orig-source target added, debian/watch file updated
* use_jinja2_to_generate_docs patch removed (incorporated upstream)
* disable_ez_setup.patch no longer needed
* make_utf8_default.patch updated
* debian/copyright file updated
* Standards-Version bumped to 3.8.3 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
                        import flash.events.MouseEvent;
2
 
                        import com.example.programmingas3.playlist.PlayList;
3
 
                        import com.example.programmingas3.playlist.Song;
4
 
                        import com.example.programmingas3.playlist.SortProperty;
5
 
 
6
 
                        // constants for the different "states" of the song form
7
 
                        private static const ADD_SONG:uint = 1;
8
 
                        private static const SONG_DETAIL:uint = 2;
9
 
                        
10
 
                        private var playList:PlayList = new PlayList();
11
 
 
12
 
                        private function initApp():void
13
 
                        {
14
 
                                // set the initial state of the song form, for adding a new song
15
 
                                setFormState(ADD_SONG);
16
 
                                
17
 
                                // prepopulate the list with a few songs
18
 
                                playList.addSong(new Song("Nessun Dorma", "Luciano Pavarotti", 1990, "nessundorma.mp3", ["90's", "Opera"]));
19
 
                                playList.addSong(new Song("Come Undone", "Duran Duran", 1993, "comeundone.mp3", ["90's", "Pop"]));
20
 
                                playList.addSong(new Song("Think of Me", "Sarah Brightman", 1987, "thinkofme.mp3", ["Showtunes"]));
21
 
                                playList.addSong(new Song("Unbelievable", "EMF", 1991, "unbelievable.mp3", ["90's", "Pop"]));
22
 
 
23
 
                                songList.dataProvider = playList.songList;
24
 
                        }
25
 
 
26
 
 
27
 
                        private function sortList(sortField:SortProperty):void
28
 
                        {
29
 
                                // Make all the sort type buttons enabled.
30
 
                                // The active one will be grayed-out below
31
 
                                sortByTitle.selected = false;
32
 
                                sortByArtist.selected = false;
33
 
                                sortByYear.selected = false;
34
 
 
35
 
                                switch (sortField)
36
 
                                {
37
 
                                        case SortProperty.TITLE:
38
 
                                                sortByTitle.selected = true;
39
 
                                                break;
40
 
                                        case SortProperty.ARTIST:
41
 
                                                sortByArtist.selected = true;
42
 
                                                break;
43
 
                                        case SortProperty.YEAR:
44
 
                                                sortByYear.selected = true;
45
 
                                                break;
46
 
                                }
47
 
 
48
 
                                playList.sortList(sortField);
49
 
                                
50
 
                                refreshList();
51
 
                        }
52
 
 
53
 
 
54
 
                        private function refreshList():void
55
 
                        {
56
 
                                // remember which song was selected
57
 
                                var selectedSong:Song = Song(songList.selectedItem);
58
 
                                
59
 
                                // re-assign the song list as the dataprovider to get the newly sorted list
60
 
                                // and force the List control to refresh itself
61
 
                                songList.dataProvider = playList.songList;
62
 
                                
63
 
                                // reset the song selection
64
 
                                if (selectedSong != null)
65
 
                                {
66
 
                                        songList.selectedItem = selectedSong;
67
 
                                }
68
 
                        }
69
 
 
70
 
 
71
 
                        private function songSelectionChange():void
72
 
                        {
73
 
                                if (songList.selectedIndex != -1)
74
 
                                {
75
 
                                        setFormState(SONG_DETAIL);
76
 
                                }
77
 
                                else
78
 
                                {
79
 
                                        setFormState(ADD_SONG);
80
 
                                }
81
 
                        }
82
 
 
83
 
 
84
 
                        private function addNewSong():void
85
 
                        {
86
 
                                // gather the values from the form and add the new song
87
 
                                var title:String = newSongTitle.text;
88
 
                                var artist:String = newSongArtist.text;
89
 
                                var year:uint = newSongYear.value;
90
 
                                var filename:String = newSongFilename.text;
91
 
                                var genres:Array = newSongGenres.selectedItems;
92
 
 
93
 
                                playList.addSong(new Song(title, artist, year, filename, genres));
94
 
 
95
 
                                refreshList();
96
 
        
97
 
                                // clear out the "add song" form fields
98
 
                                setFormState(ADD_SONG);
99
 
                        }
100
 
 
101
 
 
102
 
                        private function songListLabel(item:Object):String
103
 
                        {
104
 
                                return item.toString();
105
 
                        }
106
 
 
107
 
 
108
 
                        private function setFormState(state:uint):void
109
 
                        {
110
 
                                // set the form title and control state
111
 
                                switch (state)
112
 
                                {
113
 
                                        case ADD_SONG:
114
 
                                                formTitle.text = "Add New Song";
115
 
                                                // show the submit button
116
 
                                                submitSongData.visible = true;
117
 
                                                showAddControlsBtn.visible = false;
118
 
                                                // clear the form fields
119
 
                                                newSongTitle.text = "";
120
 
                                                newSongArtist.text = "";
121
 
                                                newSongYear.value = (new Date()).fullYear;
122
 
                                                newSongFilename.text = "";
123
 
                                                newSongGenres.selectedIndex = -1;
124
 
                                                // deselect the currently selected song (if any)
125
 
                                                songList.selectedIndex = -1;
126
 
                                                break;
127
 
                                                
128
 
                                        case SONG_DETAIL:
129
 
                                                formTitle.text = "Song Details";
130
 
                                                // populate the form with the selected item's data
131
 
                                                var selectedSong:Song = Song(songList.selectedItem);
132
 
                                                newSongTitle.text = selectedSong.title;
133
 
                                                newSongArtist.text = selectedSong.artist;
134
 
                                                newSongYear.value = selectedSong.year;
135
 
                                                newSongFilename.text = selectedSong.filename;
136
 
                                                newSongGenres.selectedItems = selectedSong.genres;
137
 
                                                // hide the submit button
138
 
                                                submitSongData.visible = false;
139
 
                                                showAddControlsBtn.visible = true;
140
 
                                                break;
141
 
                                }
142
 
                        }
143