Solved

TextFormat and XML "attributes" property conflict

Posted on 2008-10-29
10
513 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
  • 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SharePoint 2013 Blog Template 2 54
TSQL query to generate xml 4 46
JSON  parse help 7 40
XSL FO - remove empty space and automatically size columns 6 11
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,…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to how to record live broadcast.

830 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