View Full Version : automatically trigger a change handler?
finnstones
02-15-2004, 03:13 PM
how can i automatically trigger a list boxes' change handler in actioncript code, everything is lareay created, i just need the code to trigger the changehandler, i am going to insert this in an AS file which is external to my fla file.
thanks experts :)
CyanBlue
02-15-2004, 03:15 PM
I don't know what you mean 'automatically trigger', but what about just call that function once in the frame where you want it to be executed???
oldnewbie
02-15-2004, 03:27 PM
FListBox.setChangeHandler in the AS dictionary.
not sure what you mean by 'trigger', but if you want the change handler to execute, just call the function that acts as your change handler, or do something like myListbox.setSelectedIndex(0); this will trigger the change handler, cause you've changed the listbox.
is that what you mean?
finnstones
02-16-2004, 03:10 PM
tg yes you are right, however your solution does not work, i tried the below, look at the last line, neither calling the changehandler function nor setting the index triggered the change handler function which is below that
//----------------------------------------------------------------------
// initProdLB
//----------------------------------------------------------------------
CategoryUI.prototype.initProdLB = function() {
var prodNavHolder = this.productHolder_mc;
prodNavHolder._visible = false;
// :TRICKY: "Magic" postioning numbers
var prod_mcScale = 230;
var label_txtX = 5;
var label_txtY = 55;
var label_txtWidth = 75;
var label_txtHeight = 20;
var wiper_mcCenterOffset = 7;
var wiper_mcAnimationSteps = 5;
var wiper_mcAlpha = 80;
var prod_lbX = 8;
var prod_lbY = 18;
var prod_lbWidth = 162;
// Product listBox height is set with setRowCount()
var prod_lbRowCt = 7;
var bezelYOffset = -1;
var bezelHeightOffset = 1;
// :END TRICKY: "Magic" postioning numbers
var ct = 1;
var wiper_mc = prodNavHolder.attachMovie("hairlineMainBG_mc", "productChangeWiper_mc", ct++);
var prod_mc = prodNavHolder.attachMovie("catNav_btnBase_mc", "productNavBase", ct++);
prod_mc._xscale = prod_mc._yscale = prod_mcScale;
//prod_mc.createTextField("label_txt", ct++, label_txtX, label_txtY, label_txtWidth, label_txtHeight);
var itemUI_mc = itemBrowsing_mc;
//:TRICKY: Differences in the corner radii require offset.
wiper_mc.base_x = wiper_mc._x = wiper_mc.base_y = wiper_mc._y = wiper_mcCenterOffset;
wiper_mc._alpha = wiper_mcAlpha;
var point = new Object();
point.x = itemUI_mc._x;
point.y = itemUI_mc._y;
wiper_mc.steps = wiper_mcAnimationSteps;
wiper_mc._parent.globalToLocal(point);
wiper_mc.x1 = point.x;
wiper_mc.y1 = point.y;
wiper_mc.xInc = (wiper_mc.x1 - wiper_mc.base_x) / wiper_mc.steps;
wiper_mc.yInc = (wiper_mc.y1 - wiper_mc.base_y) / wiper_mc.steps;
//:TRICKY: prod_mc dimensions include dropshadow, must scale to a fraction of that size.
wiper_mc._xscale = wiper_mc.base_xScale = ((prod_mc._width * 0.85) / wiper_mc._width) * 100;
wiper_mc._yscale = wiper_mc.base_yScale = ((prod_mc._height * 0.85) / wiper_mc._height) * 100;
wiper_mc.xScaleInc = (100 - wiper_mc._xscale) / wiper_mc.steps;
wiper_mc.yScaleInc = (100 - wiper_mc._yscale) / wiper_mc.steps;
wiper_mc.counter = 1;
var prod_lb = prodNavHolder.attachMovie("FListBoxSymbol", "products_lb", ct++);
this.tabController.setTab("CategoryUI",
prod_lb, TabConstants.prototype.CategoryUIStartTab + 10);
prod_lb.setChangeHandler("prodLBChangeHandler", this);
_global.initStyles();
prod_lb.setStyleProperty("textSelected", 0xFFFFFF);
prod_lb.setStyleProperty("embedFonts", true);
prod_lb.setAutoHideScrollBar(true);
prod_lb._x = prod_lbX;
prod_lb._y = prod_lbY;
_global.sizeAndFormatListBox(prod_lb, prod_lbRowCt, ct++, prod_lbWidth);
prod_lb.setSelectedIndex(0);
this.prodLBChangeHandler();
}
****
CategoryUI.prototype.prodLBChangeHandler = function(theProd_lb) {
this.productsVisited = true;
var curr_sel_prod = theProd_lb.getSelectedItem().data;
var curr_sel_oid = curr_sel_prod["PRODUCTOID"];
if(curr_sel_oid != undefined && (curr_sel_oid != this.currentProdOID &&
(this.pendingSelProd == undefined ||
curr_sel_oid != this.pendingSelProd.getItemAt(0)["PRODUCTOID"]))) {
// <TRICKY>: Prevent the ui from getting overwhelmed by not requesting
// new prod info until the product animation stops. Remember last requested
// product so we can fire off a request when animation finishes
// Note: if we've a pending change category request, that trumps the pending
// product request so we completely ignore this event if there's pending cat change
// request.
if(!this.prodAnimBusy) {
this.prodAnimBusy = true;
this.currentProdOID = curr_sel_oid;
theProd_lb.currCatWidget.currProdOID = curr_sel_oid;
this.animateProductChange(curr_sel_prod, theProd_lb.currCatWidget.getLabel(),
theProd_lb.currCatWidget.getColor());
this.catalog.browseNewProduct(curr_sel_prod, theProd_lb.currCatWidget.getLabel(),
theProd_lb.currCatWidget.getName(),
theProd_lb.currCatWidget.getColor());
}
else if(this.pendingSelProd == undefined) {
this.pendingProdRec= { record : curr_sel_prod,
label : theProd_lb.currCatWidget.getLabel(),
name : theProd_lb.currCatWidget.getName(),
color : theProd_lb.currCatWidget.getColor() };
}
// </TRICKY>
}
}
Please format any code!! -rp
change the following and see what happens... i didn't bring my laptop home from work today, so i'm trying this without testing anything.
change:
var prod_lb=...
to:
this.prod_lb=...
then delete this line:
this.prodLBChangeHandler();
and see what happens...
first thing i notice is that in your original code, its not 'this' thats attaching the listbox, it is 'provNavHolder' so if you want to keep it with that structure, your would need to target 'provNavHolder.prod_lb' to set the selected index.
any way, my guess is that its a path issue, so if you can grok that, you should get it to work no matter how you write it.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.