Skip to main content
January 3, 2007
Answered

target_mc._height

  • January 3, 2007
  • 2 replies
  • 409 views
hi if got a little problem how can I use the target_mc._height outside of my onloadinit function? i have to add it to my var K to keep me on the right height?


var k = 10;
//variabele voor het bijhouden van de hoogte
var j = 10;
//variabele voor het bijhouden van dfe depth
function loadXML(loaded) {
if (loaded) {
myTBX.contentPath = "content_holder";
xmlNode = this.firstChild;
date = [];
titel = [];
entry = [];
image = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
date = xmlNode.childNodes.childNodes[0].firstChild.nodeValue;
titel = xmlNode.childNodes.childNodes[1].firstChild.nodeValue;
entry = xmlNode.childNodes.childNodes[2].firstChild.nodeValue;
image = xmlNode.childNodes.childNodes[3].firstChild.nodeValue;
//formatting voor datums
var my_fmt2 = new TextFormat();
my_fmt2.font = "Verdana";
my_fmt2.size = 11;
my_fmt2.underline = true;
my_fmt2.color = 0xFFCC33;
//Yellow
my_fmt2.bold = true;
var metricsDate:Object = my_fmt2.getTextExtent(date , 100);
thisTextBox = myTBX.content.createTextField("tbxDate"+i, 20+j, 20, k, 100, metricsDate.textFieldHeight);
j++;
k += 15;
//tussen titel en datum
thisTextBox.background = false;
thisTextBox.border = false;
thisTextBox.backgroundColor = 0xcccccc;
//light grey
thisTextBox.borderColor = 0x000000;
//black
thisTextBox.multiline = true;
thisTextBox.wordWrap = true;
thisTextBox.text = date
;
thisTextBox.setTextFormat(my_fmt2);
//formatting voor datums
var metricsTitel:Object = my_fmt2.getTextExtent(titel , 300);
thisTextBox1 = myTBX.content.createTextField("tbxTitel"+i, 20+j, 20, k, 300, metricsTitel.textFieldHeight);
j++;
k += 15;
//tussen titel en txt
var my_fmt3 = new TextFormat();
my_fmt3.font = "Verdana";
my_fmt3.size = 11;
my_fmt3.underline = true;
my_fmt3.color = 0xFF9900;
//orange
my_fmt3.bold = true;
thisTextBox1.background = false;
thisTextBox1.border = false;
thisTextBox1.backgroundColor = 0xcccccc;
//light grey
thisTextBox1.borderColor = 0x000000;
//black
thisTextBox1.multiline = true;
thisTextBox1.wordWrap = true;
thisTextBox1.text = titel
;
thisTextBox1.setTextFormat(my_fmt3);
var my_fmt = new TextFormat();
my_fmt.font = "Verdana";
my_fmt.size = 10;
my_fmt.color = 0x000000;
//grey
var metricsText:Object = my_fmt.getTextExtent(entry , 450);
thisTextBox2 = myTBX.content.createTextField("tbxText"+i, 20+j, 20, k, 450, metricsText.textFieldHeight);
j++;
k += metricsText.textFieldHeight;
thisTextBox2.background = false;
thisTextBox2.border = false;
thisTextBox2.backgroundColor = 0xcccccc;
//light grey
thisTextBox2.borderColor = 0x000000;
//black
thisTextBox2.multiline = true;
thisTextBox2.wordWrap = true;
thisTextBox2.html = true;
thisTextBox2.htmlText = entry
;
thisTextBox2.setTextFormat(my_fmt);
k += 15;
//eindhoogte tussen enrty
if (image != "undefined") {
var mci:MovieClip = myTBX.content.createEmptyMovieClip("mc"+i, 40+j);
j++;
var image_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {
trace(target_mc._height); // <--here i have it


};
image_mcl.addListener(mclListener);
image_mcl.loadClip(image
, mci);
mci._y = k;
mci._x = 30;

//k+= target_mc._height + 10; // <-- here's my problem


}
}
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load(" http://localhost/test/get_news_to_xml.php");
/////////////////////////////////////
This topic has been closed for replies.
Correct answer
Well, from what I read in the code you are positioning the image with the text block? There you make an error based on the fact that you expect the function to wait for the image to load and then proceed with the next block. But it doesn't. As soon as the loadClip() is fired, the for loop continues.
So, running the program gives the following results when you trace k:
k at the bottom of the for loop: 117
k at the bottom of the for loop: 188
k at the bottom of the for loop: 259
k at the bottom of the for loop: 342
k at the bottom of the for loop: 413
k at the bottom of the for loop: 496
k at the bottom of the for loop: 567
k at the bottom of the for loop: 662
k at the bottom of the for loop: 841
k at the bottom of the for loop: 948
Then the for loop ends but the MovieClipLoader is still working and then traces:
200
k in onLoadInit(): 948
200
k in onLoadInit(): 948
200
k in onLoadInit(): 948
k remains 948 there because the for loop already stopped.
So, wrong setup. You need to code this differently

I got it! thx for the help anyway ;-)

i made an extra table in my msql with my image heigt (taken and stored when uploading the image) and then send in array to my flash

so that's my working code now:

2 replies

Inspiring
January 4, 2007
Post a link to a zip with all the files (fla,images,xml).
January 4, 2007
here 's the fla,

only the fla , the xml and images are generated through php so it will work like this ;-)
and thx for the help
Inspiring
January 4, 2007
Well, from what I read in the code you are positioning the image with the text block? There you make an error based on the fact that you expect the function to wait for the image to load and then proceed with the next block. But it doesn't. As soon as the loadClip() is fired, the for loop continues.
So, running the program gives the following results when you trace k:
k at the bottom of the for loop: 117
k at the bottom of the for loop: 188
k at the bottom of the for loop: 259
k at the bottom of the for loop: 342
k at the bottom of the for loop: 413
k at the bottom of the for loop: 496
k at the bottom of the for loop: 567
k at the bottom of the for loop: 662
k at the bottom of the for loop: 841
k at the bottom of the for loop: 948
Then the for loop ends but the MovieClipLoader is still working and then traces:
200
k in onLoadInit(): 948
200
k in onLoadInit(): 948
200
k in onLoadInit(): 948
k remains 948 there because the for loop already stopped.
So, wrong setup. You need to code this differently
January 3, 2007
Hi ,
Just you change the value of k inside the onLoadInit funcion.
Look the code...
January 4, 2007
thanks for the help but it isn't working eather