Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
The SpinnerList control displays a list of items that wraps around an animated wheel. The item in the center is always the selected item. The list can be spun by upward and downward throws, or by dragging up or down to select items, or the end user can simply click to choose an item. This component must be placed inside of the SpinnerList container, and this provides the chrome and layout for the component. Now, the SpinnerList also uses an item renderer and other typical Flex conventions.
So let's explore how to use this. First thing I'm going to do is just create a brand-new Flex mobile project, and let's just call this project SpinnerList. Okay, you can choose whatever location you like. This doesn't have any dependencies. We'll use the Flex 4.6 SDK. Let's create a blank application here instead of a view-based, and we won't target the BlackBerry tablet OS for now. We'll say Next. We just leave all the defaults here and then just go ahead and click Finish. Okay.
And here's our SpinnerList application. And let's just add in a layout so we're controlling this in a vertical fashion. So, I'm just going to say s:layout, and I'm going to create a VerticalLayout, instantiate that right there, like we've done earlier, and then I'm going to simply just say paddingTop is equal to 40 pixels. We'll say the paddingBottom, well let's add in a buffer of 5 pixels and then for the paddingLeft, I'll also add in a buffer of 5 pixels there. And then the paddingRight, again 5 pixels, gap is equal to 10 pixels, and then the horizontalAlign is equal to center, and then the verticalAlign is equal to the top there, just like so. Close that.
Make sure your layout tag is closed of course. And now let's add in a SpinnerList control. So, here I'm just going to say spark and I'll say SpinnerList. First of all, let's add a SpinnerListContainer like you see there, and let's make this width is equal to, let's make our SpinnerListControl 200 pixels, just like so. And then inside of the SpinnerListContainer just place a SpinnerList. So, here I'm going to simply say s:SpinnerList, and then I'll say width is equal to 100%, like so. And then I'll specify the dataProvider and then inside of that-- and make sure, I forgot to put in my spark namespace, that'll cause me some problems, so make sure you put in your spark namespace, just like so.
Make sure I close that. Sorry! Adding in the wrong place there. So, there's my spark dataProvider, and then create an ArrayCollection inside of that dataProvider, just like so. And then let's use our code snippet to avoid the typing. So, I'm going to go back to my Exercise Files up here. I'm going to go to my code snippets. I can utilize the same code snippet, the rtf here, and I will just simply copy that and I'll just simply go back to Flash Builder and paste that right back in there.
Make sure that your last fx string is closed off. And then you have your list of different devices, just to save yourself some typing. Now, we should able to see these displayed inside of the SpinnerList. So, here I'm going to simply hit Save, and then I'm going to set up my run configuration here. I'll say Mobile Application, again Apple iOS. Let's do the iPad, and I'll click on Run. We should see our new SpinnerList container, and look at that. So, you can see the new SpinnerList container with the items that we had selected.
Now, the SpinnerList control itself works like almost every other Flex component you've already worked with and have learned about in all of the lynda.com courses. If we are displaying complex data, we can use a label field or a label function to display the properties in the complex data structure, instead of the simple strings that we're utilizing in this example. We can also access any items that the user has selected via the selected index and the selected items properties. Again, these are all covered in the basic lynda.com courses. We can also place multiple spinner applications inside of a single spinner container and we can simply just copy and paste here.
So, for example, if I just go over here and I take my SpinnerList here, I can place multiple SpinnerLists here. I'll just copy this SpinnerList and I'll place it inside of the container. There you'll see that. And let's just make sure that I set this, the width here, I'm going to set this to, say, 400 pixels. And let's make this take up half of the screen size real estate, and I'll set this up here.
So I hit Save. And then you'll see now I will have multiple SpinnerList controls, just like so, that take up that amount of real estate. And you can also add style tags directly to your SpinnerList controls as well, just like a normal Flex component. So for example, if I go up here and I add in a style tag, I can use CSS classes to customize my controls. So for example, I'll say fx:Style, just like so.
So, you'll see there right, I have my namespace there, and let's reference my spinner. So here I'll just say spark and I'll simply say SpinnerListItemRenderer, just, like so. And then I'll just define my CSS class here, and I can put my paddingTop. We'll say, :15. I can define colors, fonts, all this, and then we'll say paddingBottom.
Don't need the equal sign there, of course. So, I'll say paddingBottom. Let's define 15 again, and I'll say paddingLeft:15, and then I'll define paddingRight:15, just like so. So, there's my SpinnerLlist. I'll click on Save, and let's go ahead and just test that. You should see that this is now applied to our spinner controls, right, and you'll notice of course, we now have the spinning.
We now have the padding inside of both of the spinning controls, because we applied it directly to that class that affects all of the spinning components. So again, the SpinnerList provides a very familiar interface for tablet users and really utilizes design patterns that have been established in tablet applications.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 99141 Viewers
56 Video lessons · 112418 Viewers
71 Video lessons · 81237 Viewers
131 Video lessons · 39013 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.