Solved

TextFormat and XML "attributes" property conflict

Posted on 2008-10-29
10
510 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
Comment Utility
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
Comment Utility
oh yeah, and what was the error you got
0
 

Author Comment

by:lookouts
Comment Utility
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
 
LVL 39

Accepted Solution

by:
blue-genie earned 500 total points
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:lookouts
Comment Utility
Does anyone know?
0
 

Author Comment

by:lookouts
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry about that, you got it - your first answer was right - I just misunderstood your answer. Thanks again.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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 …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

728 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

9 Experts available now in Live!

Get 1:1 Help Now