actionscript 3 contentHeight not updating properly -
i using adobe flash builder actionscript make desktop application. getting html code webpage , putting mx:html element, attempting content height in order determine if should hide vertical scrollbar or not. however, when using contentheight seems return height of previous state of element, rather 1 set.
this code fetch html page
var htmlpagerequest:urlrequest = new urlrequest(url); htmlpagerequest.method = urlrequestmethod.get; //set request's html request method htmlpageloader.addeventlistener(event.complete, onhtmlloaded); //listen page load htmlpageloader.load(htmlpagerequest);//when loaded continue logic in new function
this function run when page request complete
private function onhtmlloaded(e:event):void { //logic after html page has loaded htmlelement.data = htmlpageloader.data; //set content //determine if vscroll bar should visible if(htmlelement.contentheight > htmlelement.height) { scrollbar.visible = true; } else { scrollbar.visible = false; } trace(htmlelement.height); trace(htmlelement.contentheight); }
i have realised solution problem:
htmlelement.data = htmlpageloader.data;
rendering html takes amount of time - contentheight being accessed before page has rendered, causing previous value returned. in order fix this, added event listener (htmlrender) in order not access contentheight until rendering complete.
private function onhtmlloaded(e:event):void { //logic after html page has loaded htmlelement.addeventlistener(event.html_render, onhtmlrendered); //once html has rendered, move on htmlelement.data = htmlpageloader.data; //render content } private function onhtmlrendered(e:event):void { //logic after page has rendered //if content of html element bigger box, show scrollbar if(htmlelement.contentheight > htmlelement.height) { scrollbar.visible = true; } else { scrollbar.visible = false; } }
Comments
Post a Comment