Flex 4.5 List - ensureIndexIsVisible error - list

In my application I have a list of items which can be changed either by clicking on the list, using a next/previous button or via a menu which allows them to jump between items (mainly for the phone version which doesn't display the list).
I'm using the ensureIndexIsVisible function after the data provider for the list has been populated. However sometimes when I return to this page the application crashes out with the following error:
RangeError: Error #1125: The index 0 is out of range 0.
at spark.layouts.supportClasses::LinearLayoutVector/getMajorSize()[E:\dev\4.y\frameworks\projects\spark\src\spark\layouts\supportClasses\LinearLayoutVector.as:420]
The strange thing is that the index I pass into the function when it crashes isn't 0. It can be 1 or 3 or presumably anything. I can stop the application from crashing if I remove the function call but I need the list to show what question is currently selected.
The actual line that crashes is this:
var block:Block = blockTable[index >> BLOCK_SHIFT]; from a function called getMajorSize

As this has gone unanswered for so long I thought I'd answer it myself back with what I've recently ended up doing.
I managed to get this issue resolved by mainly changing the points where I called the function. i.e. it was being called too early.
However I recently changed over to using a custom function that someone else posted as I found that the ensureIndexIsVisible was often jumping to the wrong position in the list (due to a variety in heights of the items).
The function can be found on this question and is called scrollToIndex:
Scroll to selected item in Flex 4 Spark List component

This error is related to FLEX-28291, which should be fixed in the next version of Apache Flex (probably 4.14).

Related

Update an element that already has a plugin

Zurb Foundation 6.5.3
I have an accordion menu which needs to be updated via ajax after the initial page load. So initially the menu contains 2 items, then $(document).foundation(); is called. Later after an ajax response is received elements are added (and potentially removed/replaced) within the menu.
I would like to be able to re-use the same elements however, I can't update the plugin to re-style the changed elements. I've tried:
$("#my-menu").foundation(); which doesn't work and shows the error:
Tried to initialize accordion-menu on an element that already has a Foundation plugin.
Foundation.reflow(menu, 'accordion'); which doesn't work.
menu.foundation('reflow'); which doesn't work and shows the error:
Uncaught ReferenceError: We're sorry, 'reflow' is not an available method for AccordionMenu.
I have made it work by destroying and removing the existing menu, re-creating the whole thing, then calling $("#my-menu").foundation(); however this isn't ideal in my opinion.
I found that my issue was due to no one solution working in all 3 cases:
foundation has not yet been initialised
foundation is initialised and the entire element has been replaced since
foundation is initialised and the element has been updated since
Unless someone has a better answer, I solved using this approach:
// this can happen before, or after code creates the menu
$(document).foundation();
console.log("foundation run");
__foundationRun = true;
...
function foundationUpdate(el) {
if (__foundationRun) {
if (el.data('zfPlugin'))
// already initialised, update it
Foundation.reInit(el);
else
// new element, initialise it
el.foundation();
}
// else leave for foundation initialise
}
....
// ... do updates (modify or replace entirely) and then:
foundationUpdate($("#my-menu"));

WTL CListViewCtrl getSelectedItem is causing an Assertion fail for me

This is my code in order to get the name of the item which has been selected in my CListViewCtrl:
LVITEM item = { LVIF_PARAM };
CString itemText;
clistViewCtrl.GetSelectedItem(&item);
clistViewCtrl.GetItemText(item.iItem, item.iSubItem, itemText);
Note that this code is working. I recently did another project, where I grabbed the name in exactly this way, however, I had no problems there with any assertion fails.
When I execute this with my current project, I always get a debug assertion:
"File: ... atlctrls.h"
Line: 3242
Expression: (GetStyle() & 0x0004) != 0
Even though the expression already states it pretty much, here is the line causing the failure:
ATLASSERT((GetStyle() & LVS_SINGLESEL) != 0);
I have barely any idea what the problem is. As I said, the exact same code worked on my other project, and I just went through both, trying to find any differences which could cause this behaviour, but nothing caught my eye.
Honestly, I don't even know if this is related to my code at all, considering the two compared elements seem to be predefined.
My first guess would have been that this part is being called before the items are created, but all items in the listview are created at the point I try to call this code passage.
Can anyone point me to a solution?
Your control is not created with style flag LVS_SINGLESEL. So calling GetSelectedItem is causing an assert. In case of multi selection use GetFirstSelectedItem and GetNextSelectedItem instead of GetSelectedItem. For single selection you can continue useing GetSelectedItem, but you have to add LVS_SINGLESEL style flag to your control.

Using polymer-gestures to test custom element

Why is this test causing the following failure and error?
expected 'NO. ONE' to equal 'ITEM TWO'
<unknown> at /swiper-slider/test/basic-test.html:59
Object.Fake.downAt at /polymer-gestures/test/js/fake.js:98
Object.Fake.downOnNode at /polymer-gestures/test/js/fake.js:89
Context.<anonymous> at /swiper-slider/test/basic-test.html:56
polymer-gestures/test/js/fake.js is failing to find the target in this method, called from this method but I can't narrow down the exact culprit.
My hunch is that it has something to do with the div.swiper-button-next element being appended as a child on the fly and use of document.querySelector('swiper-slider /deep/ div.swiper-button-next') in the test.
I have a hunch that one of a few things is happening.
the div.swiper-button-next isn't in the DOM by the time you make the call. Either work a callback into your system to fire when everything is done (then check the value inside that callback), or (just to test if this is actually the problem) put a manual setTimeout to delay the query selector and assertion for a bit.
Polymer's targetAt function uses elementFromPoint() internally. Double check to make sure you don't have any overlays (core-overlay tends to crap all over my window sometimes...) and that the element you really want to tap is actually the element being found. Don't be afraid to put some debugging/console.log statements into the actual polymer source code to see what it is finding there.
I haven't spent too much time looking over the test, but your slideEls[1] could possibly have changed since you queried for it. querySelectorAll returns a "non-live" nodelist, so changes to the DOM don't update your selection.

Google Geocoder Returning null From Reverse Lookup

I am trying to use the Google geocoder to do a reverse-geocoder lookup. I am running the exact same command on 8 values, and I am only having an error on two of them, which has me confused as one of the failing values is identical to one of the working values. (The 'working' values aren't really working- they still return a value of undefined from the 'formatted_address' field, but they aren't throwing errors). The command that I am running is as follows:
geocoder.geocode({latLng: new google.maps.LatLng(machineList[i].y, machineList[i].x)}, function(results, status) { address = results[0]; });
I am receiving a type error from Javascript, claiming that results is null. I'm not sure why this is happening. Any ideas?
Well, it turns out this was a timing issue. The geocode() command was taking longer to complete for certain locations than for others, which caused the value to show up as null. I ended up eliminating the problem by moving all the subsequent code into the callback function (I hadn't done this earlier because the whole thing is running inside of a loop, and I was having some difficulty getting it to pass in the iterator as a parameter). Now everything seems to be working well and the locations are showing up as they should.

Changing the Total Number of Recent Files

I'd like the user to be able to edit the number of recent files shown in the File menu of my MFC application. I've used two very good references:
http://www.codeproject.com/KB/menus/changemru.aspx
http://www.microsoft.com/msj/0899/c/c0899.aspx
It involves deleting and recreating the CRecentFileList object stored in CWinApp::m_pRecentFileList. Unfortunately, I find that the menu is not updated properly after replacing the CRecentFileList. See code snippet below:
void CMyWinApp::SetMRUListSize( int size )
{
// size guaranteed to be between 1 and 16
delete m_pRecentFileList ;
LoadStdProfileSettings( size ) ;
}
What can I do to ensure that what is drawn into the File menu is synchronized with m_pRecentFileList after I recreate the object?
My CApp derives from CWinApp. In initInstance, you have this line:
LoadStdProfileSettings(10);
At the end of InitInstance, add this code:
m_pmf->m_pRecentFileList = m_pRecentFileList;
Here m_pmf is my MainFrame class and I created a member CMainFrame::m_pRecentFileList of type CRecentFileList which is in the MFC source file filelist.cpp. m_pRecentFileList on the right is protected and CMainFrame doesn't have access to it from outside InitInstance, but you can make a functional copy here.
At the end of CMainFrame::OnClose, force a registry update by:
m_pRecentFileList->WriteList();
// Force registry update on exit. This doesn't work without forcing.
I don't even have to rebuild m_pRecentFileList, the MRU mechanism updates it correctly. Example: 5 MRU items, the first is moved to another directory and can no longer be found. Stepping through the code in the debugger shows that the bad entry is removed from the list. For some reason, the updated list isn't saved correctly unless I force it as explained above. I originally thought the problem might have something to do with privileges (64-bit Win7), but running the app as admin didn't help.
Some of Microsoft's documentation suggest you should call CWinApp::LoadStdProfileSettings from within InitInstance. This suggests to me that it's something done once during initialisation rather than at run time.
Have you tried fully implementing the second of the two links you provided? My guess is you need to add the second part instead of the call to CWinApp::LoadStdProfileSettings:
m_pRecentFileList = new CRecentFileList(0, strSection, strEntryFormat, nCount);
if(m_pRecentFileList)
{
bReturn = TRUE;
// Reload list of MRU files from registry
m_pRecentFileList->ReadList();
}
[Edit] Apparently m_pRecentFileList points to an CRecentFileList Class . Have you tried calling CRecentFileList::UpdateMenu?
There's another CodeProject example which might help too.