Solved

TextFormat and XML "attributes" property conflict

Posted on 2008-10-29
10
515 Views
Last Modified: 2013-11-11
I added a TextFormat object to my Actionscript, but it's causing errors. (The errors go away once I remove the code that creates the new TextFormat object.)

The problem is that Actionscript compiler is not recognizing my attributes settings from my XML file after creating the TextFormat object.

Also, there's an alignment attribute in an XML element in my XML file that looks like this -  alignment="center".

I trimmed down the code in my snippet below, but the compiler threw no errors in the past as I had height, y and border attributes set (the errors didn't show up when I didn't include the new TextFormat object).

function loadXML(loaded) {
 
	if (loaded) {
		
		if (this.firstChild.firstChild.childNodes.length == 4) {
			// code that generates movieclips
			
			// card_front is the path to access the attributes for "fronts" in the XML doc  
			card_front = this.firstChild.firstChild;
			card_back = this.firstChild.firstChild.nextSibling;
 
			card_front_alignment = card_front.attributes.alignment;
			card_back_alignment = card_back.attributes.alignment;
 
                        var card_front:TextFormat = new TextFormat();
                        var card_back:TextFormat = new TextFormat();
			card_front.align = card_front_alignment;
			
			_root.card1.card1_front.text_card1_front.setTextFormat(card_front);
			_root.card2.card2_front.text_card2_front.autoSize = card_front_alignment;
			_root.card3.card3_front.text_card3_front.autoSize = card_front_alignment;
			_root.card4.card4_front.text_card4_front.autoSize = card_front_alignment;
			_root.card1.card1_back.text_card1_back.autoSize = card_back_alignment;
			_root.card2.card2_back.text_card2_back.autoSize = card_back_alignment;
			_root.card3.card3_back.text_card3_back.autoSize = card_back_alignment;
			_root.card4.card4_back.text_card4_back.autoSize = card_back_alignment;
			
			// other code...
		}
	}
 
}
var urls:Array = new Array();
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("flashcards.xml");

Open in new window

0
Comment
Question by:lookouts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 39

Expert Comment

by:blue-genie
ID: 22843980
hello. am i understanding correctly?
you're using an xml file to parse through txtformat data to your TextFormat class?
the snippet your provided, does that throw an error?
can you upload your xml file?
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 22843987
oh yeah, and what was the error you got
0
 

Author Comment

by:lookouts
ID: 22885724
blue-genie, the XML is pretty much the same as my previous post, the error message I got was the following:
---
Line 12: There is no property with the name 'attributes'.
---
The snippet does throw an error - I trimmed it down a bit, though.

I'm using TextFormat to center text on the flashcards...
<?xml version="1.0"?>
 
<flashcards>
	<fronts height="120" y="-60" border="" alignment="center">
		<card1_front title="">Turner Field</card1_front>
		<card2_front title="Stadium">Pro Player Stadium</card2_front>
		<card3_front title="Stadium">Comisky Park</card3_front>
	</fronts>
	<backs height="120" y="-60" border="" alignment="center">
		<card1_back title="Team">Braves</card1_back>
		<card2_back title="Team">Marlins</card2_back>
		<card3_back title="Team">White Sox</card3_back>
	</backs>
	<main>
		<main_text height="30" y="10" border="">Welcome to the flashcards example. This is just a template. See the instructions in the XML doc to learn how to setup this file.</main_text>
		<instructions_text height="20" y="80" border="">Click each Flashcard to proceed through the exercise.</instructions_text>
	</main>
</flashcards>

Open in new window

0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 39

Accepted Solution

by:
blue-genie earned 500 total points
ID: 22892650
ok don't know what else is supposed to happen afterwards, but to get rid of the error message, declare your variables with their datatypes.
i.e.
var card_front:XMLNode;
var card_back:XMLNode;
before you loadXML method.
0
 

Author Comment

by:lookouts
ID: 22898229
Do I have to import a class first? Like import flash.display.TextFormat;?

I'm still getting those error messages, Flash is not liking the attributes property for some reason. I can post my entire code, but it's about 500 lines.
0
 

Author Comment

by:lookouts
ID: 22924610
Does anyone know?
0
 

Author Comment

by:lookouts
ID: 22924640
All I want to do is align my dynamic text fields, and control it from an XML document with an alignment attribute.

1. Set alignment attribute in XML doc to "center"
2. Get Flash to display the dynamic text field's text centered
3. Also, would like to control the size of text from XML doc using a size attribute much the same way as steps 1 and 2.
0
 

Author Closing Comment

by:lookouts
ID: 31511194
Thanks, blue-genie, the only thing that threw me off was "before you loadXML method". It gets rid of the error messages but I'm not getting any alignment. I'll figure it out eventually. Thanks again.
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 22991769
hi sorry didn't get back earlier. last couple of days have been manic.
I've not worked much with textformats but no you shouldn't need to import it.
if you want me to have a look (no promises) will you zip up the file and upload it (add a .txt ext to the end of the .fla)

blu.
0
 

Author Comment

by:lookouts
ID: 22997942
Sorry about that, you got it - your first answer was right - I just misunderstood your answer. Thanks again.
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
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…

689 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