Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 10-08-2008, 05:42 AM   #1
inhan
it's all about patience
 
inhan's Avatar
 
Join Date: Jun 2005
Location: istanbul
Posts: 6,696
Default [AS2] List component - setting initial selection

I had been trying to figure out how to make an automatic selection of an item in a List component and I figured it out after messing with it for some time. This script makes the desired item in the list selected as soon as it loads. If listeners are associated with the component instance, 'itemRollOver' and 'change' events are also triggered if available.

I thought someone else might need it so here it is.

ActionScript Code:
myList.doLater(this, "selectInitialItem"); // change 'myList' above to the List instance of yours var initIndex:Number = 0; // initial index of the List instance to be activated function selectInitialItem() {     var list:mx.controls.List = myList;     // change 'myList' above to the List instance of yours     var s:Number = initIndex;     if (initIndex == undefined || initIndex < 0) s = 0;     else if (initIndex > list.dataProvider.length-1) {         s = list.dataProvider.length - 1;     }     list["content_mc"]["listRow"+(10+s)].bG_mc.onRollOver();     list["content_mc"]["listRow"+(10+s)].bG_mc.onPress();     list["content_mc"]["listRow"+(10+s)].bG_mc.onRelease();     list.selected = {};     list.selected[s.toString()] = s;     list.onMouseUp(); }
__________________
Ali Inhan
Turkish graphic and web designer
an Apple fan
www.aliinhan.com

Last edited by inhan; 10-08-2008 at 06:38 AM. Reason: added a little comment in code, line 2
inhan is offline   Reply With Quote
Old 10-08-2008, 08:29 PM   #2
inhan
it's all about patience
 
inhan's Avatar
 
Join Date: Jun 2005
Location: istanbul
Posts: 6,696
Default

I just figured out something. The 'selectedIndex' property sets the item at index 'selectedIndex' selected, but it doesn't trigger the 'itemRollOver' or 'change' events. So the difference between assigning it a number and using the script above is basically this.
__________________
Ali Inhan
Turkish graphic and web designer
an Apple fan
www.aliinhan.com
inhan is offline   Reply With Quote
Old 03-21-2009, 03:58 PM   #3
squadjot
Senior Member
 
Join Date: Nov 2003
Posts: 362
Default

Nice, info on the AS2 components are always good to have..

I'll add this to my list of Components: tips and tricks
squadjot is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[AS2] Displaying images in a List component Aeros Components 1 09-14-2008 04:41 PM
Custom Component with List carriker Components 0 11-01-2006 04:27 PM
List Component Selection Without Shift? LittleDan Components 0 10-03-2006 08:41 PM
event listener list component & remoting data mantra Flash Remoting 0 07-20-2006 01:52 PM
List Selection Box Kallisto ActionScript 1.0 (and below) 2 10-13-2001 12:13 AM


All times are GMT. The time now is 08:00 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.