PDA

View Full Version : Height of a MovieClip with dynamically loaded content



MRPLC
September 15th, 2009, 12:50 PM
Hi, I have a movieclip that contains TextFields containing XML data, when I trace the height of the MovieClip externally, the original height (before the XML is loaded) is returned.

How can I get the new height of the MovieClip, (I am trying to align the Movieclip vertically to the centre of the stage)?

Thanks.

jhvh1134
September 15th, 2009, 02:17 PM
Are you making sure that the XML is fully loaded before grabbing data? If not, try setting up an event listener to trigger your function with the resize when the XML is fully loaded.

MRPLC
September 15th, 2009, 04:23 PM
Hi, thanks for your response, the MovieClip is in my library, with all the loading code inside an actions layer inside it. The code that adds the MovieClip to the stage (via addChild), is in a separate .as file. I guess the problem at the moment is that as I am adding the MovieClip, and setting it's y-position at the same time, the MovieClip hasn't loaded all the data. Is is possible to add an event listener to the MovieClip, or would my structure make it problematic?

Cheers.

jhvh1134
September 15th, 2009, 05:52 PM
cant really tell with out seeing your code.

MRPLC
September 15th, 2009, 06:50 PM
Thanks again for a response.

Here's some of the code placed inside the MovieClip, pertaining to the XML loading:


var contact_xml:XML;
var xmlReq:URLRequest = new URLRequest("XML/contacts.xml");
var xmlLoader:URLLoader = new URLLoader();

xmlLoader.load(xmlReq);
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(event:Event):void
{
contact_xml = new XML(xmlLoader.data);
contact_xml.ignoreWhitespace = true;
my_contact = contact_xml.contact;
my_department = contact_xml.contact.department;
my_email = contact_xml.contact.email;
my_total_contact = my_contact.length();
my_total_department = my_department.length();
my_total_email = my_email.length();
contact_title_text.htmlText =contact_xml.title;
contact_title.y = 0;
contact_title.theTitle.blendMode = BlendMode.LAYER;
contact_title.theTitle.wordWrap = true;
contact_title.theTitle.selectable = false;

makeContainers();
callTextBoxes();

xmlLoader.removeEventListener(Event.COMPLETE, xmlLoaded);
xmlLoader=null;
}Then I'm just creating an instance of the MovieClip, and adding it to the stage.

Cheers!

Scythe
September 15th, 2009, 08:01 PM
Try putting this at the end of your xmlLoaded function:


y = stage.stageHeight / 2 - height / 2;

MRPLC
September 16th, 2009, 04:25 AM
Thanks a lot, I think I had a massive flu-induced/sleep-deprived brain-freeze yesterday, as after a good night's sleep, I also came to the same conclusion, i.e. setting the y-value inside the MovieClip itself.

Cheers!