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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you make two HTML files load in your .fla file?

Status
Not open for further replies.

Q1475

Technical User
Mar 19, 2008
22
0
0
US
I need to have more than one external html file load in my flash website file. I have tried to create two LoadVars and when I added the code for the second html text it not only didn't work but it caused my other html file to not work.

I am new to flash and this is my first time building a website on my own. Can anyone give me a sample of how to write this actionscript code for more than one html dyamic text boxes with css attached.

My two sections so far that have external html files are a news section where a swf file loads and plays an animated pic that transitions out to be able to read helpful tips in a textbox with a scroll bar.

And the next section is a case study.

This is frustrating please help!
 
Frame 1:

// create a variable for a StyleSheet object and name it cssStyles
var cssStyles:TextField.StyleSheet = new TextField.StyleSheet();
// load the external style sheet into memory
cssStyles.load("NewsFlash Info.css");
// after attempting to load the style sheet, execute the
// function and pass on whether loading was a success or not
cssStyles.onLoad = function (success) {
// if informed that the style sheet loaded successfully apply the
// style sheet to the dynamic text box textInfo and then load the
// external text file into memory and notify the myLoadVars function
// in keyframe intro if loading the text file was successful or not
if (success) {
webNewsinfo.styleSheet = cssStyles;
_root.myLoadVars.load("webNewsinfo.txt");
// if the style sheet did not load successfully
// display an error message in webNewsinfo
} else {
webNewsinfo.text = "An error occurred loading the requested content.";
}
}

mcStudyinfo TEXT SYMBOL: (on a action layer inside)

// create a variable for a StyleSheet object and name it cssStyles
var cssStyles:TextField.StyleSheet = new TextField.StyleSheet();
// load the external style sheet into memory
cssStyles.load("NewsFlash Info.css");
// after attempting to load the style sheet, execute the
// function and pass on whether loading was a success or not
cssStyles.onLoad = function (success) {
// if informed that the style sheet loaded successfully apply the
// style sheet to the dynamic text box textInfo and then load the
// external text file into memory and notify the myLoadVars function
// in keyframe intro if loading the text file was successful or not
if (success) {
webNewsinfo.styleSheet = cssStyles;
_root.myLoadVars.load("webNewsinfo.txt");
// if the style sheet did not load successfully
// display an error message in webNewsinfo
} else {
webNewsinfo.text = "An error occurred loading the requested content.";
}
}

WebContentinfo TEXT SYMBOL: (on a action layer inside)

// create a variable for a StyleSheet object and name it cssStyles
var cssStyles:TextField.StyleSheet = new TextField.StyleSheet();
// load the external style sheet into memory
cssStyles.load("NewsFlash Info.css");
// after attempting to load the style sheet, execute the
// function and pass on whether loading was a success or not
cssStyles.onLoad = function (success) {
// if informed that the style sheet loaded successfully apply the
// style sheet to the dynamic text box textInfo and then load the
// external text file into memory and notify the myLoadVars function
// in keyframe intro if loading the text file was successful or not
if (success) {
webNewsinfo.styleSheet = cssStyles;
_root.myLoadVars.load("webNewsinfo.txt");
// if the style sheet did not load successfully
// display an error message in webNewsinfo
} else {
webNewsinfo.text = "An error occurred loading the requested content.";
}
}
 
I don't know why you are duplicating the same script across 3 timelines, but that is a bad practice.

Do it all from the main timeline (or external Class). You only need one script to control any number of TextFields (or anything) on Stage.

Kenneth Kawamoto
 
oops sorry, i am not duplicating, i just pasted the text wrong. ;-)Duhhh!

Frame 1 looks like this:

stop();
// create a variable for a LoadVars function and name the variable myLoadVars
var myLoadVars:LoadVars = new LoadVars();
// when myLoadVars is called from Frame 1 of symbol webcontentInfo execute this function
myLoadVars.onLoad = function (success) {
// if the external text file was loaded into memory successfully load the text into
// the dynamic text box webNewsinfo
if (success) {
_root.webcontentInfo.webNewsinfo.htmlText = myLoadVars.webNewsinfo;
// if the text file did not load successfully display an error message in webNewsinfo
} else {
_root.webcontentInfo.webNewsinfo.text = "An error occurred loading the requested content.";
}
}

// create a variable for a LoadVars function and name the variable LoadVarsCase
var LoadVarsCase:LoadVars = new LoadVars();
// when LoadVarsCase is called from Frame 1 of symbol mcStudyinfo execute this function
LoadVarsCase.onLoad = function (success) {
// if the external text file was loaded into memory successfully load the text into
// the dynamic text box caseStudyMC
if (success) {
_root.StudyinfoMC.caseStudyMC.htmlText = LoadVarsCase.caseStudyMC;
// if the text file did not load successfully display an error message in caseStudyMC
} else {
_root.StudyinfoMC.caseStudyMC.text = "An error occurred loading the requested content.";
}
}

MAX Cat Study textbox has code inside and looks like this:

// create a variable for a StyleSheet object and name it cssStyles
var cssStylescase:TextField.StyleSheet = new TextField.StyleSheet();
// load the external style sheet into memory
cssStylescase.load("CaseStudy Info.css");
// after attempting to load the style sheet, execute the
// function and pass on whether loading was a success or not
cssStylescase.onLoad = function (success) {
// if informed that the style sheet loaded successfully apply the
// style sheet to the dynamic text box caseStudyMC. and then load the
// external text file into memory and notify the LoadVarsCase function
// in keyframe intro if loading the text file was successful or not
if (success) {
caseStudyMC.styleSheet = cssStylescase;
_root.LoadVarsCase.load("caseStudyMC.txt");
// if the style sheet did not load successfully
// display an error message in caseStudyMC.
} else {
caseStudyMC.text = "An error occurred loading the requested content.";
}
}

Web News textbox field has code inside that looks like this:
(which you already seen three times in the previous post)

// create a variable for a StyleSheet object and name it cssStyles
var cssStyles:TextField.StyleSheet = new TextField.StyleSheet();
// load the external style sheet into memory
cssStyles.load("NewsFlash Info.css");
// after attempting to load the style sheet, execute the
// function and pass on whether loading was a success or not
cssStyles.onLoad = function (success) {
// if informed that the style sheet loaded successfully apply the
// style sheet to the dynamic text box textInfo and then load the
// external text file into memory and notify the myLoadVars function
// in keyframe intro if loading the text file was successful or not
if (success) {
webNewsinfo.styleSheet = cssStyles;
_root.myLoadVars.load("webNewsinfo.txt");
// if the style sheet did not load successfully
// display an error message in webNewsinfo
} else {
webNewsinfo.text = "An error occurred loading the requested content.";
}
}
 
Still I'd do this from the main timeline, but let's have a look :)

First I would not have "NewsFlash Info.css" as a CSS file name. "newsflash_info.css" is a better choice.

Then place "trace()" everywhere so that you can tell where it's failing. e.g.
Code:
if (success) {
trace(cssStyles.getStyleNames());
...


Kenneth Kawamoto
 
Well, I am a newbie, this is my first website I have ever built on my own, and I was following a book on how to add html text to a flash movie.

(Visual Quick Project-"Creating a Web Site with Flash CS3 Professional")

That is how they instructed me to do it. Then I added another text file and I began to have problems. First with the scrollbars not working, then I got that to work and now I can't get my Web News text to appear after viewing the other text file for my MC Case Study text. If I never view the MC Case Study text info I will be able to get the text to show up, but once I take a look at that MC Case Study Text, bye bye WebNews Text. What a pain! I am not giving up though!

Thanks for all your help. I am going to try what you suggested and will write what happens as a result.
 
By the way, did you check out the link and look through the website? Did you see the problem?
 
I don't know If I did this correctly, because that didn't work.

I added the code where I thought it was supposed to go, in the two places where the css styles code was located in the both textfields action layers.

All I received was a message in the output "undefined"

The same problem is occurring.

I also tried to copy and paste all the code from the other two places into Frame 1 of my movie and the html text did not show up at all. So it is not meant to have all the code in one frame in the timeline.

Just so you can maybe understand better, these textfields are all in the same timeline in the same main movie. The action code is just in different places within the movie.

This is an exceptionally challenging issue and have posted this problem in other forums and have yet to come up with an answer. I have seen other websites with more than one textbox with a scrollbar and so I am sure I am able to accomplish this goal of having multiple external html files loaded in a file.

I hope you can still try to help me! :)
 
Of course you can have any number of texts in a Flash movie, do not worry.

> All I received was a message in the output "undefined"

That's good, because now we know it is not working at your code level.

To make things clearer, can you create a fresh FLA with just one text and show us the code?



Kenneth Kawamoto
 
Made a new fresh new flash file with two layers (with just one text). One with my symbol that includes the textbox and scrollbar component. And another actions layer.

The symbol edit mode contains two layers. One with the text and scrollbar symbol. Another actions layer.

The symbol name is "WebContentinfo"
The symbol instance name is "webcontentInfo"
The text instance name is "webNewsinfo"
The text file name is "webNewsinfo"
The css file name is "newsflash_info"

Frame 1 in main timeline:
Code:
stop();
// create a variable for a LoadVars function and name the variable myLoadVars
var myLoadVars:LoadVars = new LoadVars();
// when myLoadVars is called from Frame 1 of symbol webcontentInfo execute this function
myLoadVars.onLoad = function (success) {
	// if the external text file was loaded into memory successfully load the text into
	// the dynamic text box webNewsinfo
	if (success) {
		_root.webcontentInfo.webNewsinfo.htmlText = myLoadVars.webNewsinfo;
		// if the text file did not load successfully display an error message in webNewsinfo
	} else {
		_root.webcontentInfo.webNewsinfo.text = "An error occurred loading the requested content.";
	}
}

Symbol with instance name webcontentInfo:

Code:
// create a variable for a StyleSheet object and name it cssStyles
var cssStyles:TextField.StyleSheet = new TextField.StyleSheet();
// load the external style sheet into memory
cssStyles.load("newsflash_info.css");
// after attempting to load the style sheet, execute the
// function and pass on whether loading was a success or not
cssStyles.onLoad = function (success) {
	// if informed that the style sheet loaded successfully apply the
	// style sheet to the dynamic text box textInfo and then load the
	// external text file into memory and notify the myLoadVars function
	// in keyframe intro if loading the text file was successful or not
	if (success) {
		webNewsinfo.styleSheet = cssStyles;
		_root.myLoadVars.load("webNewsinfo.txt");
	// if the style sheet did not load successfully
	// display an error message in webNewsinfo
	} else {
		webNewsinfo.text = "An error occurred loading the requested content.";
	}
}
 
I made another flash file with the same code and two texts and it works without all the rest of the elements, layers, and actions from the main site. It works fine!

Now to only make it work in my main flash file.

The issue seems to be maybe where my textfield is located in my flash main site or maybe it is just the convaluted mess that makes up the rest of my site.

I do have a swf movie that is loaded just before you see the text and that caused an issue cuz the loader component does not disappear so I had to hodge podge and fake it out so the buttons make the movie reload. It's crazy! I know I could use the movieloader function in actionscript but I am not sure I am able to place it in a certain spot on my stage so I ruled that way out. I need the swf movie to load in a certain place and the loader component made it easy for me to put it in a certain specific place on my stage.

Anyway, I am going to try and put all my case study info and webnews info that deals with my two html files in a new scene to see if that works. Well, see if that works.
 
I figured it out, in case you were still interested. I had actioncode that was duplicated in another area. What a dope! Well, I must have accidentally placed it there. Gosh, I feel so dumb but so happy at the same time. :)
 
Thanks for all your help Kenneth.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top