Listbox selectedindex property change doesn't update the UI - scripting

Using javascript, I am trying to change the selection of the listbox item like this:
function selectFirstActiveListItem(oListBox)
{
for (var i = 0; i < oListBox.options.length; i++)
{
oListBox.selectedIndex = i;
var szStatus = GetDomboBoxItemAttribute("Status", m_pdocConnectType.getXMLDOM(), oListBox);
if ("Enabled" == szStatus)
return;
}
oListBox.selectedIndex = 0;
}
Though the index correctly changes at the background, but it is not reflected on the UI. The listbox still shows the old selection.
What's going wrong?

try this instead:
oListBox.options[i].selected = true;

Oops! That was working and showing the correct result. My take on the behavior was incorrect there.

Related

Livecycle: Referencing objects in repeated subforms

I have a form that I want to lock for presentation once it is filled out. I know how to make this happen with a button to render the text fields read-only. Now I have a form that involves repeated subforms (added as needed). How can I script a single button so it will work for the objects in all the subforms?
The subforms are iterations of "ItemGroup". I need to make "ItemGroup.Item" and "ItemGroup.ItemRx" read-only, and "ItemGroup.ItemHeader.Button" invisible.
I'm at home, hence untested. Let me know if you bump into trouble.
var sfSom = "<path/somExpression to subform containing ItemGroups>"; var nn, n = xfa.resolveNode(sfSom).nodes;
for (var i = 0; i < n.length; i++) {
nn = n.item(i);
if (nn.name == "ItemGroup" && nn.className == "subform") {
/* change stuff here. Decide if Item and ItemRx should be read-only, calculate or protected. For now, we'll settle for hiding the button: */
nn.ItemHeader.Button.presence = "hidden";
}
}

AS2 Attaching a Bitmap to Dynamic created Variables

I'm stuck with this problem and simply cannot get it solved, sorry if there was another post about this already but I couldn't find it as well.
On to the problem then: I'm trying to make a simple function capable of initializing and updating bitmaps, and a few other variables I haven't thought of yet, when needed.
I created on the stage some MovieClips called slot0, slot1, slot2 etc... inside another MovieClip called ButtonRootPannel in order to have a visual of where I'll be putting the images without having to guess numbers in the code.
Together with those I set up this code:
var buttons_rootArray:Array = new Array;
for(var i=0;i<=11;i++){
this["slot"+i] = this.ButtonRootPannel.createEmptyMovieClip("slot"+i, i);
this["slot"+i].customState = "Inactive"; //Active, Inactive or Unavaiable
this["slot"+i]._x = eval("_root.ButtonRootPannel.slot"+i)._x;
this["slot"+i]._y = eval("_root.ButtonRootPannel.slot"+i)._y;
this["slot"+i]._width = eval("_root.ButtonRootPannel.slot"+i)._width;
this["slot"+i]._height = eval("_root.ButtonRootPannel.slot"+i)._height;
buttons_rootArray.push(this["slot"+i]);
}
UpdateButtonsSlot(0,"BuildButton");
UpdateButtonsSlot(1,"CancelButton");
function UpdateButtonsSlot(slot:Number, newImage:String):Void{
var tempData:BitmapData = BitmapData.loadBitmap(newImage);
var tempClip:MovieClip = eval(buttons_rootArray[slot]);
//buttons_rootArray[slot].unloadMovie();
//buttons_rootArray[slot].clear();
tempClip.attachBitmap(tempData,this.getNextHighestDepth(),"auto",true);
}
Anyone knows what I might be doing wrong?
Thanks in advance.
Well, problem solved, this now seems to be working for some strange reason:
for(var i=0;i<=11;i++){
var currentMC = eval("_root.ButtonRootPannel.slot"+i);
this["slot"+i] = this.ButtonRootPannel.createEmptyMovieClip("slot"+i, i);
this["slot"+i].customState = "Inactive"; //Active, Inactive or Unavaiable
this["slot"+i]._x = currentMC._x;
this["slot"+i]._y = currentMC._y;
//this["slot"+i]._width = currentMC._width;
//this["slot"+i]._height = currentMC._height;
buttons_rootArray.push(this["slot"+i]);
}
Only those commented lines makes the MovieClip disappear if I uncomment them. Will just leave them out then and problem solved.

Programmatically scrolling WPF 4 DataGrid to end

Does anyone know of a reliable approach for scrolling a WPF DataGrid (.NET 4) to the last row programmatically?
I'm aware of ScrollIntoView(Items[Items.Count-1]), but this works only if the items are unique.
For instance, consider the following DataGrid which displays all the installed cultures, followed by all the installed cultures:
var cultures = System.Globalization.CultureInfo.GetCultures (System.Globalization.CultureTypes.AllCultures);
var timesTwo = cultures.Concat (cultures).ToArray();
var grid = new DataGrid { ItemsSource = timesTwo };
How can this grid be programmatically scrolled to the last row?
P.S. Another problem with using ScrollIntoView is that if the grid is itself in a scrollable container (e.g., inside another grid), then ScrollIntoView scrolls not only its own grid, but the outer grid as well such that requested element is visible on the screen. This might be beneficial in some cases, but certainly not in others.
For anyone with this problem, the following seems to do the trick:
var scrollerViewer = GetScrollViewer();
if (scrollerViewer != null) scrollerViewer.ScrollToEnd();
...
ScrollViewer GetScrollViewer()
{
if (VisualTreeHelper.GetChildrenCount (this) == 0) return null;
var x = VisualTreeHelper.GetChild (this, 0);
if (x == null) return null;
if (VisualTreeHelper.GetChildrenCount (x) == 0) return null;
return VisualTreeHelper.GetChild (x, 0) as ScrollViewer;
}

JSFL: selecting items returned by fl.findObjectInDocByType()

I can't seem to use the info returned by fl.findObjectInDocByType() with fl.getDocumentDOM().selection.
I want to use document.setTextRectangle to re-size some text fields from an array generated using fl.findObjectInDocByType().
I can easily access all the textObject properties but since document.setTextRectangle requires a current selection, I am at a loss.
The example in the documentaion for setting selection is:
fl.getDocumentDOM().selection = fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0];
fl.findObjectInDocByType() returns an array of objects with the attributes: (object.timeline, object.layer, object.frame, object.parent)
But these are objects, and don't have a property for array index numbers required by fl.getDocumentDOM().selection=...
var doc = fl.getDocumentDOM();
var textFieldArray = fl.findObjectInDocByType("text", doc);
for (var i=0; i < textFieldArray.length; i ++){
fnResizeTheTextField(textFieldArray[i]);
}
function fnResizeTheTextField(theTextField){
//force current selection to be theTextField
//doc.selection MUST be an array, so assign theTextField to an array...
var selectArray = new Array();
selectArray[0] = theTextField.obj;
var theTimeline =theTextField.timeline;
var theLayer =theTextField.layer;
var theFrame =theTextField.frame;
doc.currentTimeline =theTextField.timeline;
doc.selection = doc.getTimeline().theLayer.theFrame.selectArray;//error
//resize the text rectangle
doc.setTextRectangle({left:0, top:0, right:1000, bottom:1000});
}
}
Result: Error:doc.getTimeline().theLayer has no properties
It turns out, the ObjectFindAndSelect.jsfl script already contains a function specifically for this: fl.selectElement(). Much more elegant:
var doc = fl.getDocumentDOM();
// generate an array of elements of type "text"
var textFieldArray = fl.findObjectInDocByType("text", doc);
for (var i=0; i < textFieldArray.length; i ++){
fnResizeTheTextField(textFieldArray[i]);
}
function fnResizeTheTextField(theTextField){
//force current selection to be theTextField
fl.selectElement(theTextField,false);//enter 'edit mode' =false...
//resize the text rectangle
doc.setTextRectangle({left:0, top:0, right:1000, bottom:1000});
}
}
I found the answer. In order to select anything for a document level operation, you have to also make flash focus on the keyframe of that object.
so, if I loop through an array of objects created by fl.findObjectInDocByType(), I use this code to make flash focus on the object correctly:
function fnMakeFlashLookAt(theObject){
doc.currentTimeline =theObject.timeline;
doc.getTimeline().currentLayer =theObject.layer;
doc.getTimeline().currentFrame =theObject.frame;
}
this may not work on objects nested inside a symbol however.
I had a similar issue recently, and apparently all google results about setTextRectangle() direct us here. It's unbelievable how poorly documented jsfl is :)
If you need to use setTextRectangle() inside an library item that is not on stage, you need to open for edit the item first.
Here's the code that solved my problem:
library.selectItem(libraryItemName);
doc.selection = [tf];//where tf is the reference to textfield we need to edit
doc.library.editItem(libraryItemName);
doc.setTextRectangle({left:l, top:t, right:r, bottom:b});
doc.selectNone();
If you have a better working solution, please post. I hope it saves somebody's time. Good luck!

Finish control loading

I've a method which fill a combobox. (compact framework 3.5)
lstNiveaux.BeginUpdate();
lstNiveaux.Items.Clear();
for (int i = 0; i < list.Count; i++)
{
var item = new ListViewItem(list[i].value);
lstNiveaux.Items.Add(item);
}
lstNiveaux.EndUpdate();
I want to do :
lstNiveaux.Items[10].Selected = true;
lstNiveaux.EnsureVisible(10);
When I write that piece of code at the end of the previous method, it won't work but ... if I put a button with a click event, and the piece of code inside, it will work.
I tryied Application.DoEvents, Thread.Sleep and other stuff but no work. Does someone has a solution ?
regards