Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-12-2007, 07:58 AM   #1
Lycanthropy
Registered User
 
Join Date: Nov 2007
Posts: 15
Default Identifiers in ActionScript

It seems like i need to use MovieClips from the library where the linkage identifier is set, to add icons to my list component.

Code:
/**
 Requires:
  - List component on Stage (instance name: my_list)
  - MovieClip/Graphic symbol in the Library with Linkage ID of "flash"
  - MovieClip/Graphic symbol in the Library with Linkage ID of "dreamweaver"
  - MovieClip/Graphic symbol in the Library with Linkage ID of "cf"
*/

var my_list:mx.controls.List;

my_list.setSize(200, 100);

my_list.addItem({data:"flash", label:"Flash", icon:"flash"});
my_list.addItem({data:"dreamweaver", label:"Dreamweaver", icon:"dreamweaver"});
my_list.addItem({data:"coldfusion", label:"ColdFusion", icon:"cf"});

my_list.iconField = "icon";
Is there a way to sett the MovieClip Identifier from ActionScript and not do it manualy in the library?
Lycanthropy is offline   Reply With Quote
Old 11-12-2007, 11:54 AM   #2
emergency_pants
Today I smell of toast
 
Join Date: Dec 2002
Location: London, UK
Posts: 1,053
Default

If you had thirty symbols in your library, how would you be able to tell flash which symbol in your library was the right one to rename with your actionscript? Probably with some sort of... erm... identifier?

So, the answer is no. Sorry.

I suppose, if you need to create new identifiers dynamically, you could write the library identifier strings into an array and set an ID to each, so you could then dynamically set the ID value of each identifier to whatever you want and get at the correct identifier by lokoing it up in the array. Not sure it's worth the hassle though!
__________________
Cheers,

Simon.

Last edited by emergency_pants; 11-12-2007 at 12:01 PM.
emergency_pants is offline   Reply With Quote
Old 11-12-2007, 04:01 PM   #3
Greg SS
Uber sleepy
 
Join Date: Nov 2007
Location: Bandung
Posts: 886
Send a message via Yahoo to Greg SS
Default

The only way to add icons, If you need to set icons for your list component from a collection of movieclip that are not defined at design time (ie. no identifier), is by creating a custom cellRenderer class.
Read cellRenderer API in the ActionScript component help file for more description.
You need to modify the sample provided there to make it work with a list, and a workaround hack to "create" a movieclip from existing movieclip.
Since there is no way (that I know of) to copy an existing movieclip into a different parent movieclip (no, duplicate wont work, since it will create a duplicate under the same parent), you have to play around with BitmapData, and copy the content of the existing MovieClip as a bitmap snapshot into an empty movieclip made under a different MovieClip (this sucks ).

Code:
import flash.display.BitmapData;

class CustomSelectableRow extends mx.core.UIComponent{
	private var rowLabel;
	private var owner;
	private var listOwner;
	private var icon_mc;
	
    private static var PREFERRED_HEIGHT_OFFSET = 4; 
    private static var PREFERRED_WIDTH = 100;
    private var startDepth:Number = 1;

	public function CustomSelectableRow(){
	}
	
    public function createChildren():Void
    {
        var c = rowLabel = this.createLabel("rowLabel", startDepth);
        c.styleName = listOwner;
        c.selectable = false;
        c.tabEnabled = false;
        c.background = false;
        c.border = false;
    }
    public function size():Void
    {
        var c = rowLabel;
        rowLabel.setSize(__width, __height);
    }
    public function getPreferredHeight():Number
    {
        return owner.__height - PREFERRED_HEIGHT_OFFSET;
    }

    public function setValue(itmObj:String, item:Object, selected:Boolean):Void
    {
		var h = __height;
		var o = owner
		var c = rowLabel;
		var icon = listOwner.getItemAt(o.rowIndex).icon;
		if (icon==undefined) {
			icon = o.getStyle("defaultIcon");
		}

		var i = icon_mc;
		if (icon!=undefined && itmObj!=undefined) {
//			i = createObject(icon, "icon_mc", 20);
			var bd:BitmapData = new BitmapData(icon._width, icon._height, true, 0);
			bd.draw(icon);
			i = this.createEmptyMovieClip("icon_mc", 20);
//			i = icon.duplicateMovieClip("icon_mc", 20); //DO NOT WORK!!!!!!!!!!!!!!!
			i.attachBitmap(bd, 20);
			icon_mc = i;
			i._x = 2;
			i._y = (h - i._height) / 2;
			c._x = 4 + i._width;
		} else {
			i.removeMovieClip();
			c._x = 2;
		}
		
        if (item==undefined){
            rowLabel.text._visible = false;
        }
        rowLabel.text = itmObj;
    }
}
On your main timeline:

Code:
myList.addItem({data:"flash", label:"Flash", icon:icon_1});
myList.addItem({data:"dreamweaver", label:"Dreamweaver", icon:icon_2});
myList.addItem({data:"coldfusion", label:"ColdFusion", icon:icon_3});

myList.iconField = "icon";

myList.cellRenderer = "CustomSelectableRow";
Notice that there is no quotes around the icon properties, its a direct reference to movieclips on-stage.
Greg SS 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
I'm beginner in actionscript. I have questions. helgso ActionScript 1.0 (and below) 7 06-16-2006 04:11 PM
Flash Actionscript Career Advice? bdemil General Chat 3 06-15-2006 06:35 PM
Need Help! displaying external text files Flash_Boi ActionScript 2.0 7 03-30-2006 08:23 PM
ActionScript Confusion stanonbass ActionScript 1.0 (and below) 7 12-07-2004 08:16 PM
Actionscript book cheezisgoooood ActionScript 1.0 (and below) 2 02-06-2003 11:31 PM


All times are GMT. The time now is 09:26 AM.

///
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.