Solved

TextFormat and XML "attributes" property conflict

Posted on 2008-10-29
10
514 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

738 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