Solved

loading vars from xml

Posted on 2008-06-12
8
145 Views
Last Modified: 2010-04-21
Hi-
I am dynamically loading text in flash (see code below) and everything in working well. I need to take this code to the next level and have the ability the change the color (my_fmt.color = 0xC30000;) dynamically as well. Maybe loading it from the same XML or read the querystring in the html or maybe a seperate XML file...

I am new to flash and just don't know how to start...

Thanks in advance


var my_fmt:TextFormat = new TextFormat();

my_fmt.bold = true;

my_fmt.font = "MyAllStar"; /* this is the LinkageID not the symbol name. */

my_fmt.size = 24;

my_fmt.color = 0xC30000;

this.createTextField("new_txt", this.getNextHighestDepth(), 10, 10, 100, 200);

new_txt.setNewTextFormat(my_fmt);

new_txt._rotation = 00;

new_txt._alpha = 100;

new_txt.autoSize = true;

new_txt.embedFonts = true;
 

PreviewerContent = new XML();

PreviewerContent.ignoreWhite = true;

PreviewerContent.load("Previewer.xml");

PreviewerContent.onLoad = function(success)

{

	if(success)

	{

		new_txt.text = PreviewerContent;

		

	}

}

Open in new window

0
Comment
Question by:doctor069
  • 4
  • 4
8 Comments
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 21775841
I'd use the same xml file if it is convenient.

can you post a copy of your xml file?

this might be an example of what you'd use:

<?xml version="1.0" encoding="UTF-8"?>
<flash>
      <textbox1>
            <text>this goes in textbox 1</text>
            <font_colour>0xC30000</font_colour>
      </textbox1>
</flash>

0
 

Author Comment

by:doctor069
ID: 21775917
I really dont have much of an xml file
in fact it is just text, not really even a xml file...
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 21776061
that's ok so do you want to keep the text file the way it is and have a separate real xml file for the configuration?  i'm not sure how you've set it up but in this case it may work to have 2 separate files.

xml is good as it gives you more ability to control and structure your flash
0
 

Author Comment

by:doctor069
ID: 21778332
i think XML would be best
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 21787450
would you like to have everything in the one xml file?  this would work if the text isn't too long.  if you have paragraphs and paragraphs of text then it might be better to leave it as a separate file and just have a small xml file to configure stuff
0
 

Author Comment

by:doctor069
ID: 21788318
Hi the max the textbox will be is 10 words so everything in one file should be ok...
0
 
LVL 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 125 total points
ID: 21790106
if you use my xml example above and a combination of your code you should be able to get this working quite quickly

>>> the xml

<?xml version="1.0" encoding="UTF-8"?>
<flash>
      <textbox1>
            <text>this is all your text that you have in the file at the moment</text>
            <font_colour>0xC30000</font_colour>
      </textbox1>
</flash>
// and the actionscript

// i've made embedFonts=false and font=Arial just for testing
 

this.createTextField("new_txt", this.getNextHighestDepth(), 10, 10, 100, 200);

PreviewerContent = new XML();

PreviewerContent.ignoreWhite = true;

PreviewerContent.load("xmlload.xml");

PreviewerContent.onLoad = function(success) {

	if (success) {

		var txt:String = (this.firstChild.firstChild.childNodes[0].firstChild.nodeValue);

		var col:String = (this.firstChild.firstChild.childNodes[1].firstChild.nodeValue);

		var my_fmt:TextFormat = new TextFormat();

		my_fmt.bold = true;

		my_fmt.font = "Arial";

		/* this is the LinkageID not the symbol name. */

		my_fmt.size = 24;

		my_fmt.color = Number(col);//0xC30000;

		new_txt.setNewTextFormat(my_fmt);

		new_txt._rotation = 0;

		new_txt._alpha = 100;

		new_txt.autoSize = true;

		new_txt.embedFonts = false;

		new_txt.text = txt;//PreviewerContent;

	}

};

Open in new window

0
 

Author Closing Comment

by:doctor069
ID: 31466814
Work perfect thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now