Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing an externally loaded movie's dynamic text box.

Status
Not open for further replies.

theweb1

Programmer
Jun 4, 2007
6
US
I'm having a ton of trouble accessing an externally loaded movie's dynamic textbox to try and change its content from a parent movieclip.

Here's the code from the parent movie movie.

clipOuterContainer.createEmptyMovieClip("clipInnerContainer",0);

clipOuterContainer.clipInnerContainer.loadMovie("childMovie.swf",0);

//following is the line that tries to reference and change
//the content of a dynamic text box called "loadedInfo",
//which is inside of childMovie.swf.
//
//THIS IS THE LINE THAT DOES NOT WORK!!!
clipOuterContainer.clipInnerContainer.loadedInfo.htmlText = "SKW";

Why won't appending ".loadedInfo.htmlText" onto the end of the loader movieclip (clipInnerContainer) let me access the dynamic text box within the external movie?

I've been struggling with this for close to 9 hours. I've GOT to be able to move forward. Can someone please help?


Thanks,
Steve
 
You cannot access the text box in the loaded child movie, until you're sure the movie is fully loaded, and certainly not on the following line of the loadMovie action.

You have to use some preloading code, and be sure the movie is fully loaded, before you can attempt to change the text.

Posting a link to your .flas might be better, if you still can't get it going...


Regards. FLASH HELP - OPENED FOR BUSINESS!
TO GET YOUR OWN FREE WEBSITE HOSTING
 
Code:
clipOuterContainer.createEmptyMovieClip("clipInnerContainer",0);
clipOuterContainer.clipInnerContainer.loadMovie("childMovie.swf",0);
clipOuterContainer.clipInnerContainer.loadedInfo.htmlText = "SKW";
This will not work because when you assign the htmlText to the TextField childMovie.swf is not yet loaded therefore the TextField does not exist (yet).

You must wait for the external movie to get loaded fully before doing anything with it. Try this:
Code:
clipOuterContainer.createEmptyMovieClip("clipInnerContainer", 0);
clipOuterContainer.clipInnerContainer.loadMovie("childMovie.swf", 0);
onEnterFrame = function () {
	if (clipOuterContainer.clipInnerContainer.getBytesLoaded()>=clipOuterContainer.clipInnerContainer.getBytesTotal()) {
		clipOuterContainer.clipInnerContainer.loadedInfo.htmlText = "SKW";
	}
};
Or better still, use MovieClipLoader Class.

Kenneth Kawamoto
 
Is the fact that I'm not using a preloader, IN AND OF ITSELF, the problem? or is that condition preventing me from seeing the REAL problem.

Also, regarding the preloader, is it enough to insert some code like:

while (clipOuterContainer.clipInnerContainer._framesLoaded != clipOuterContainer.clipInnerContainer._totalFrames) {
//keep the parent movie busy until the child movie
//is finished loading;
}

before the line that tries to access the child movie's dynamic text box?

OR,

Should I set up the classic type of preloader which involves two frames in a "preloader scene",
where the preloader scene loops between frame1 and frame2.

In other words ...

Frame1 of the first scene checks if the external movie has been loaded and if so, jumps to frame1 of the second scene.

Frame2 of the first scene jumps back to frame1 of the first scene (thereby continuing the loop.)

One last thing. Is it possible to throw an onEnterFrame into the loader movieclip's instance (clipInnerContainer) which keeps checking for this._framesLoaded==this._totalFrames and then sets a boolean flag variable in the parent movie once the external movie is fully loaded? Then perhaps the parent movie can simply keep a watch over the flag variable.

The concern I have about using a preloader is that I want the loading of one of several external movies to be triggered by onPress event listeners, and so I need a clean way to get into a frame-looping (preloader) scenario every time an onPress triggers an external movie to start loading.

Do you know if there's any pre-canned code for a scrollable text box (complete with dragbar) which loads one of several external movies (each containing an external text box) into a designated loader clip (all the externals will be using the same loader clip) based upon which button has been clicked?

Thanks,
Steve
 
kennethkawamoto,

I'm a bit confused. Does the onEnterFrame code you just gave me get attached to the loader clip as in onClipEvent(enterFrame) {...}, or does it go on the parent movie's timeline?

I just tried inserting the code into the parent movie's timeline and it didn't work.

Is there, perhaps, a way I can email you both the parent and child fla's? I'm really stuck, and I'm on time deadline to get something out.

Thanks,
 
I added the code to the _parent timeline (frame 1), but still "no go".

I even tried doing a frame loop between frame1 and frame2 of the main timeline--put a gotoAndPlay(3)into the if statement part of the code you gave me, and added a gotoAndPlay(1) to frame 2 of the main timeline, in order to keep re-evaluating the load state of the child movie.

That didn't work either!

I'm really stuck. Do you have an email, perhaps, that I can send you the two fla files. By the way. This is just an experimental setup. Once I have a working model, I'm going to set up the actual movie.

Thanks,
Steve
 
1. Un-embed fonts from "loadedInfo" TextField in your "childMovie.fla"

2. This is the only script you need. In the frame 1 of the main timeline:
Code:
clipOuterContainer.createEmptyMovieClip("clipInnerContainer", 0);
clipOuterContainer.clipInnerContainer.loadMovie("childMovie.swf", 0);
onEnterFrame = function () {
	if (clipOuterContainer.clipInnerContainer.getBytesLoaded()>=clipOuterContainer.clipInnerContainer.getBytesTotal()) {
		if (clipOuterContainer.clipInnerContainer.loadedInfo) {
			clipOuterContainer.clipInnerContainer.loadedInfo.htmlText = "SKW";
			play();
			delete onEnterFrame;
		}
	}
};
stop();
I used "loadMovie" because you used it in your code, but the best way really is to use MovieClipLoader Class; for your future reference.

Kenneth Kawamoto
 
Kenneth

That piece of code worked fine. Now, in the actual Flash movie, the assignment statement that copies the text ("SKW" string) into the dynamic text box (loadedInfo) needs to be inside of an if statement, which in turn is inside of an onLoad event listener (which is tied to a loadvariable object called myLV)

So, I inserted the onEnterFrame event listener into the actual Flash movie, replaced the assignment statement ("SKW") with a load instruction (which triggers the onLoad event handler) and then put the SKW assignnment statement inside of the if within the onLoad event listener. And, the code did not work anymore, yet it worked fine when I inserted the assignment statement into the onEnterFrame event listener. I'm fairly sure that the problem is being caused by moving the assignment statement to inside of the onLoad event listener's if statement. Can you help me with the scoping issue that I can finally move foward on this project? Thanks,

Steve

The code is below:

//strict-typed variables to be used later in the movie
var scrollDirection:String;
var scrollBarMax:Number = _root.scrollDown._y - _root.scrollTrackbar._y - _root.scrollTrackbar._height

//creates a new loadVars object that will load the text
var myLV:LoadVars = new LoadVars();
scrollTrackColor = new Color (scrollTrackbar.scrollBar);
myLV.onLoad = function(success) {
if (success) {
_parent.clipOuterContainer.clipInnerContainer.loadedInfo.htmlText = myLV.info;
_root.loadedInfo.scroll = 1;
_root.scrollTrackbar.scrollBar._y = 0;
scrollCheck();
_root.scrollUpYBox.text= _root.scrollUp._y
_root.scrollDownYBox.text= _root.scrollDown._y
_root.scrollTrackBarYBox.text = _root.scrollTrackbar._y
} else {
_parent.clipOuterContainer.clipInnerContainer.loadedInfo.text = "There has been an error loading the requested information. Please contact the Webmaster and report your error.";
};
}

clipOuterContainer.createEmptyMovieClip("clipInnerContainer",0);
clipOuterContainer.clipInnerContainer.loadMovie("loadedInfo.swf",0);
//automatically starts the loading of "stillBlue.txt" when the movie loads
onEnterFrame = function () {
if (clipOuterContainer.clipInnerContainer.getBytesLoaded()>=clipOuterContainer.clipInnerContainer.getBytesTotal()) {
if (clipOuterContainer.clipInnerContainer.loadedInfo) {
//clipOuterContainer.clipInnerContainer.loadedInfo.htmlText = "Testing...";
clipOuterContainer.clipInnerContainer.loadedInfo.htmlText="Testing...";
delete onEnterFrame;
}
}
};

//myLV.load("stillBlue.txt");


//defines function called scrollCheck() (with no parameters)
function scrollCheck() {
if (loadedInfo.maxscroll == loadedInfo.scroll) {
scrollUp.enabled = false;
scrollUp.alpha = 50;
scrollDown.enabled = false;
scrollDown._alpha = 50;
scrollTrackbar.scrollBar.enabled = false;
scrollTrackbar.scrollBar._alpha = 50;
} else {
scrollUp.enabled = true;
scrollUp._alpha = 100;
scrollDown.enabled = true;
scrollDown._alpha = 100;
scrollTrackbar.scrollBar.enabled = true;
scrollTrackbar.scrollBar._alpha = 100;
}
}

//defines another function called scrollText() (also with no parameters)
function scrollText() {
_root.onEnterFrame = function() {
//checks to see if the scrollDirection variable has been set to "up" by a button
if (scrollDirection == "up") {
loadedInfo.scroll -= 1;
//checks to see if the scrolldirection variable has been set to "down" by a button
} else if (scrollDirection == "down") {
loadedInfo.scroll += 1;
}
scrollPercent = ((loadedInfo.maxscroll-loadedInfo.scroll) / (loadedInfo.maxscroll-1));
scrollTrackbar.scrollBar._y = scrollBarMax - (scrollBarMax*scrollPercent);
};
}



 
Now you're dealing with two asynchronous functions: one is loading an external data with LoadVars, the other is loading an external SWF.

I would do these two things sequentially. First load the data with LoadVars. Then onLoad, fire the function to load the SWF - but use MovieClipLoader Class. loadMovie is for Flash 3 (and up to 6). Then finally onLoadInit populate the TextField with the data.

Using this approach ensures that when you populate the TextField both external data and SWF have been fully loaded.

Kenneth Kawamoto
 
1. Re: Load the data with LoadVars
Question: Currently, the onLoad handler puts EITHER the loaded text or an error message into the dynamic text box, depending on whether the text load was successful. Now, IF I try the sequential approach (where the dynamic text box is not yet defined because the swf is not yet loaded), won't I then need a way of communicating the success of the loadvars text load over to the movieClipLoader so the movieClipLoader knows whether to put the actual loaded text or an error message into the loadedInfo dynamic text box once the dynamic text box actually DOES get defined (AFTER the swf is loaded)?


Is there, perhaps, a way of designating a string variable (initialized to null or some dummy value) and then, in the event of an error at the loadvars stage, assign the string variable a quoted error message string? Then, after the movieClipLoader loads the swf, and right before it assigns the dynamic text, it can check to see if an error message was stuffed into that string variable prior to doing its thing?


Re: onLoadInit
Question: The definition of the movieClipLoader class indicates that the method which first waits for the ENTIRE movieclip to be loaded is onLoadComplete, and not onLoadInit (which is called already when only the first few frames have been loaded). Don't I want the entire swf movieclip to be loaded (as opposed to just the first few frames) PRIOR to accessing the dynamic text box within the swf movieclip?


Re: The over-all sequential approach
Question: This may be all well and good for a one-time load of external text into a dynamic text box, but my scenario contains user buttons alongside of the text box, which do guess what, load other swfs, and then load external text into the dynamic text boxes that are defined within those swf's.


In other words.
1. The user clicks a button
2. The button's onPress listener loads the appropriate external text, and then loads a designated swf (containing a dynamic text box)
3. The onPress then assigns the externally loaded text to the loaded swf's dynamic text box.

How will the frame-based code to do this stuff sequentially get re-triggered every time the user clicks/presses one of the side buttons? Can I simply do a gotoAndPlay back to the frame containing the code? And, were I to do that, is the onPress that triggers the re-playing of the frame with the sequential code going to limit the scope that the movieClipLoader will have access to?

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top