Sunday, March 25, 2007

Using Flash Components (Flash mx2004 - Flash 8)

Component, seen them for quite sometime, didint manage to figure how to use them, except for the button, the code to use seems so hard to understand. Well been reading 'wiley flash actionscript8 bible' and it sort of made things clear. So heres how to experiment with component

  1. Add a 'combobox' component and call the instance 'vid_ccb'
  2. Add a 'label' call it 'selVid_txt'
  3. Add a 'List' call it 'vList'
  4. Add 'label' call it 'selVidLs_txt'
  5. Add a number stepper, call it 'nStep'
  6. Add 'label' call it 'nstep_txt'
  7. add a 'window' call it 'vWin'
Ok All components are nicely loaded to the stage. it should look something like this:-



Next, create 2 smily faces (size it to 10x10 pixel) as the list uses icons, so u need to make 2 MC of smily faces, and ensure under linkage properties, its like this. Note i have 2 smily faces for first one the linkage identifier is 'icon_sm1' and second one is 'icon_sm2'



Next is the Codes. Copy and paste the actionscript to a new layer. code is simple, easy for your to figure out..(btw, im actually trying to make a video player with a playlist, work in progress)

//combo box setup

_root.vid_ccb.addItem("video 1", 1);
_root.vid_ccb.addItem("video 2", 2);
vid_ccb.dataProvider = [{label:"video 1", data:1}, {label:"video 2", data:2}, {label:"video 3", data:3}];
var oListener:Object = new Object();
oListener.change = function(oEvent:Object):Void {
if (oEvent.target._name == "vid_ccb") {
selectVidItem = vid_ccb.selectedItem.label;
_root.selVid_txt.text = selectVidItem;
}
if (oEvent.target._name == "vList") {
selectLsItem = vList.selectedItem.label;
_root.selVidLs_txt.text = selectLsItem ;
vWin.visible = true
vWin.title = selectLsItem
}
if (oEvent.target._name == "nStep") {
nstep_txt.text = nStep.value
}
};
oListener.click = function(oEvent:Object):Void {
if (oEvent.target._name == "vWin") {
oEvent.target.visible = false
}
}
_root.vid_ccb.addEventListener("change", oListener);
_root.selVid_txt.autoSize = true;
vList.dataProvider = [{label:"video 1", data:1, icon: "icon_sm1"},
{label:"video 2", data:2, icon: "icon_sm2"},
{label:"video 3", data:3, icon: "icon_sm2"},
{label:"video 4", data:4, icon: "icon_sm1"},
{label:"video 5", data:5, icon: "icon_sm1"},
{label:"video 6", data:6, icon: "icon_sm2"},
{label:"video 7", data:7, icon: "icon_sm1"}
];
vList.addEventListener("change", oListener);
vList.iconField ="icon";

vList.multipleSelection = true; //to allow multiple selection via ctrl btn
_root.nStep.minimum = 0
_root.nStep.maximum = 100
_root.nStep.stepSize = 10
nStep.addEventListener("change", oListener);

vWin.visible = false

vWin.closeButton = true
vWin.addEventListener("click", oListener);








No comments: