Load multiple parts of an XML file into one dynamic Text Field
Hi I am trying to load text from an external XML file into a dynamic text box. I have so far managed to load single parts of the XML file into a dynamic text field. I now want to be able to load different parts of the XML file (something similar to a string with appendText) into the same text Field.
I have so far managed to achive this using the String and append text properties, but would like to use XML file to do it instead.
Any tips please?
Thanks
In essence you can just do:
TextField.text = XML.node1 + XML.node2;
Similar Messages
-
Connecting a CSS doc to an XML file, in a dynamic text field in Flash
Hi all,
I am trying to connect a CSS file such that it applies it
self to the content of an XML file, viewed inside a dynamic text
field. So far I have managed to gather the code that "calls" the
contents of the XML file and also the code that calls the CSS file.
However, when I test the flash movie I get "undefined" instead of
the actual copy.
Attached then is the the AS code, XML file, and CSS file. I
hope you could help me connect everything together.
And of course, THANKS!!
-----AC------
Scrolling Text XML by Digital Science |
www.digitalscience.za.org
/////////////Load XML Data/////////////
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
header = [];
txt = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
header
= xmlNode.childNodes.childNodes[0].firstChild.nodeValue;
txt
= xmlNode.childNodes.childNodes[1].firstChild.nodeValue;
gotoAndStop(11);
} else {
errorMsg.text = "Error loading XML";
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("ewmn_content.xml");
stop();
import TextField.StyleSheet;
var ss:StyleSheet = new StyleSheet();
ss.onLoad = function() {
txt_mc.styleSheet=this; // where yourTF is your textfield
ss.load("jokes.css"); // where yourSS.css is your css file.
-----XML----------
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="jokes.css"?>
<JOKES>
<ONE>Tirza Sapir</ONE>
<JOKE>Founder and choreographer of the RikudNetto dance
group, teacher and lecturer, researcher, documenter and
choreographer within the framework of Eshkol-Wachman Movement
Notation. She was Head of the School of the Arts of Dance at the
Seminar Hakibbutzim College of Education, 2000–2007, where
she established the Dance Theatre and the Practicing Teachers
courses, and specialized training in Teaching and Treatment of
Learning Disabilities by means of Eshkol-Wachman Movement Notation.
She has written three books containing the movement scores of dance
suites: Birds, Landscapes, and Hanukka Notebooks. Member of the
Movement Notation Society, 1968–2008. Student and colleague
of the late Professor Noa Eshkol who was the co-founder and
inventor of Eshkol-Wachman Movement Notation.</JOKE>
<ONE>Sharon Reshef-Armony</ONE>
<JOKE>Head of the School for the Arts of dance at the
Kibbutzim College of Education in Tel Aviv. Teaches EWMN,
dance-theatre and composition. Choreographer of theatre plays and
film. Selected works: Hunger (Tmuna Theatre 2003-09), Film - Live
(Haifa Theatre 2007-08), Yakish & Pupche (Gesher Theatre
2007-09), Children of a lesser God (Beer Sheva Theatre 2008-09).
M.Ed (1997) from Lesley College MA in Creative Arts in Learning.
Doctoral student at ResCen, Middlesex University/ London.
Dancing in Rikudnetto group since 1990.</JOKE>
<ONE>Tally Ronen</ONE>
<JOKE>M.Ed. at Lesley University in Integrating Arts in
Learning.
Educational instructor at Kibbutzim College of Education and
teaching dance in schools and at Clore Center, Upper Galilee. Dance
choreographer for children.
Dancing in Rikudnetto group since 1991.</JOKE>
<ONE>Nira Al-Dor, Ph.D</ONE>
<JOKE>20 years of Teaching EWMN at the School of the
Dance Arts in Kibbuzim College of Education and at the School of
Arts in Tel Aviv. Her study was focused on the impact of learning
EWMN on the development of coordination.
Dancing in Rikudnetto group since 1986.</JOKE>
<ONE>Henner Drewes</ONE>
<JOKE>Lectures at the Kibbutzim College of Education in
Tel Aviv on dance and notation related technology. In 2008 he
started working as a research assistant at Salzburg University in
the project Visualizing Dance Archives.
He was awarded the Tanzwissenschaftwpreis NRW, Germany 2006
for his research on 3D representation of movement and notation.
Ph.D. (2002) at the University of Leipzig. He is the author
of the software EW Notator, a 'word-processor' for creating EWMN
scores.</JOKE>
<ONE>Shlomit Ofer</ONE>
<JOKE>M.A. at Haifa University at the Faculty of
Education with distinction, and currently doctoral student there.
Educational instructor and teacher of EWMN at Kibbutzim
College of Education. Staging performances of dance theatre in the
community.
Dancing in Rikudnetto group since 1993.</JOKE>
<ONE>Lilach Shalit</ONE>
<JOKE>M.A. in Expressive Therapies with specialization
in dance-movement therapy at Lesley University.
Educational instructor and teacher of EWMN in the course for
Dance-Theatre at Kibbutzim College of Education. Also teaching EWMN
in the School for Advanced Studies of the college, course for
Learning Disabilities, and at Orot College.
Dance-movement therapist and team coordinator at 'Tom' school
for learning disabilities and owner of a private clinic for
dance-movement therapy.
Dancing in Rikudnetto group since 1998.</JOKE>
<ONE>Michal Manor-Amir</ONE>
<JOKE>M.A. at the University of Leeds (Bretton Hall
College and Israel Extention) in Arts Education specialization in
Dance. Doctoral student at the Hebrew University of Jerusalem, in
the Faculty of Humanities, the School of Education.
Teaching movement in the Kibbutzim College of Education
within preparatory courses of Dance, Dance-Theatre and within the
Preschool course.
A corrective teacher through movement and EWMN in elementary
and high schools, and a national teacher-instructor at the dance
supervisor's office in the Israeli ministry of education.
Dancing in Rikudnetto group since 1998.</JOKE>
<ONE>Amit Chesny-Bahari</ONE>
<JOKE>B.Ed. at Kibbutzim College of Education.
Teaching movement and dance to preschool and high school
children.
Dancing in Rikudnetto group since 2004.</JOKE>
<ONE>Orly Yaakov</ONE>
<JOKE>B.Ed. at Kibbutzim College of Education, and
graduating from the special education faculty.
Teaching EWMN and creative movement at elementary schools as
well as special education school for children ages 6-21 with medium
to deep retardation. Also teaching creative movement and
preparation for ballet to preschool children.
Dancing in Rikudnetto group since 2006.</JOKE>
</JOKES>
------CSS-----
JOKE
COLOR: #333333;
DISPLAY: block;
FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
WHITE-SPACE: normal;
font-size: 11px;
MARGIN-BOTTOM: 15px;
BODYBLD
COLOR: #990000;
DISPLAY: block;
FONT-SIZE: 11pt;
FONT-WEIGHT: bold;
MARGIN-BOTTOM: 0px
BODYBOLDUN
COLOR: #00CCFF;
DISPLAY: block;
LINE-HEIGHT: normal;
MARGIN-BOTTOM: 10px;
TEXT-ALIGN: left;
font-size: 11px;
text-decoration: underline;
font-weight: bold;
ONE
COLOR: #00CCFF;
DISPLAY: block;
LINE-HEIGHT: normal;
TEXT-ALIGN: left;
font-size: 14px;
font-weight: bold;
white-space: normal;
QUESTION
COLOR: red;
DISPLAY: block;
FONT-FAMILY: Arial;
FONT-SIZE: larger;
FONT-VARIANT: normal
TITLE
COLOR: black;
DISPLAY: block;
FONT-FAMILY: 'Arial Black';
FONT-SIZE: 14pt
CATEGORY
FONT-FAMILY: Arial;
FONT-SIZE: 8pt;
FONT-VARIANT: small-caps;
TEXT-TRANSFORM: uppercaseIn essence you can just do:
TextField.text = XML.node1 + XML.node2; -
How can I load a .TXT file into a dynamic text box?
I am sure that many people know how to load a .txt file into
a dynamic text box. But I do not. I want to be able to reference a
txt file from the server into the text box. So that when I change
the text file it changes in the flash movie without even editing
the flash file itself. Thank you.http://www.oman3d.com/tutorials/flash/loading_external_text_bc/
I think this is the simplest way to go :) -
How to merge many XML files into one?
Hi: I got a small project to combine many XML files into one and convert the combined XML file in Excel using AppleScript. My XML files look like this:
<?xml version="1.0" encoding="UTF-8"?>
<Metadataobject>
<from>[email protected]</from>
<jobname>B3_IM09MBDUF</jobname>
<pages>2</pages>
<priority>3</priority>
<timezone>CEST</timezone>
<year>2013</year>
<month>7</month>
<day>15</day>
<hour>11</hour>
</Metadataobject>
and like this...
<?xml version="1.0" encoding="UTF-8"?>
<Metadataobject>
<from>[email protected]</from>
<jobname>P1_FR1330G006007_Kate_van der Vaart</jobname>
<pages>2</pages>
<priority>1</priority>
<timezone>CEST</timezone>
<year>2013</year>
<month>7</month>
<day>12</day>
<hour>16</hour>
</Metadataobject>
I get many XML files like this. And I want them to be combined and shown like this:
<?xml version="1.0" encoding="UTF-8"?>
<Metadataobject>
<job id="1">
<from>[email protected]</from>
<jobname>B3_IM09MBDUF</jobname>
<pages>2</pages>
<priority>3</priority>
<timezone>CEST</timezone>
<year>2013</year>
<month>7</month>
<day>15</day>
<hour>11</hour>
</job>
<job id="1">
<from>[email protected]</from>
<jobname>P1_FR1330G006007_Kate_van der Vaart</jobname>
<pages>2</pages>
<priority>1</priority>
<timezone>CEST</timezone>
<year>2013</year>
<month>7</month>
<day>12</day>
<hour>16</hour>
</job>
</Metadataobject>
And finally the combined XML file converts in Excel sheet with column headings "Job ID", "From", "Job Name" and so on...
Or there is another best way to get the same result...
ThanksThat is just an intermediary state to get to the excel version. Actually I get many small XML files (as shown above) from client and I want them all combined in an excel sheet with common column headings... like this...
from
jobname
pages
priority
timezone
year
month
day
hour
id
[email protected]
B3_IM09MBDUF
2
3
CEST
2013
7
15
11
1
[email protected]
B3_IM09MBDUF
2
3
CEST
2013
7
15
11
2
Thanks for your response. -
Loading multiple data from a XML file?
Hi,
I'm having trouble loading multiple data from the same XML file. In this XML file I have a list of dishes I want to add into a menu. So, how can I load multiple data from different branches of the XML file into my text fields?
Thanks in advance,
Rafael CarignatoI'm not quite sure what you are trying to do. I have this working with a .JSON file that loads "multiple" date into "multiple" fields in Edge - Is that what you mean?
Here's an example:
$.getJSON('slides.json', function(data) {
for(var i=0; i<data.length; i++)
var s = sym.createChildSymbol("slide", "stage");
s.$("photo").css({"background-image":"url('"+data[i].image+"')"});
s.$("title").html(data[i].title);
s.$("price").html(data[i].price);
s.getSymbolElement().css({"position":"absolute",
"left": i*225+50+"px",
"top":"100px"});
Each name above (photo, title, price) has an element on the stage (or in my case, a symbol) and my .JSON file has has a "branch" for each of these:
"image" : "images/7783.jpg",
"title" : "SNOCONUTS",
"price" : "12.00"
Hope that helps...
James -
How to import multiple XML files into one inDesign document without copy/paste ?
I use InDesign CS6, and I have several XML files with the same structure. Only the data are different.
I created an Indesign layout with some tagged placeholder frames on merge mode, for automated layout.
Today for each XML file I have to create a new InDesign document to import the XML. Everything works fine. Then in order to have all Indesign layouts one after the other into a single Indesign layout, I have to use the copy/paste function.
I mean for example, copy the contents of all documents to the first one. Or add pages of other documents to the first one, then delete spaces between each page.
So my question is the following:
How to repeat this process without copy/paste function, knowing that the
number of XML files could be unknown.
Thank you very much for your answer.Yes, effectively I would like to catalogue the files into one collection so i can save as one PDF and Print as one.:)
I know I could save each AI as a pdf them then merge the pdf's together in acrobat, but I have nearly 100 files so would feel more comfortable seeing them all together before print / saving.
My concern is that if I insert them in Ai, will the file resolution reduce? and will the ai still be editable and would it update the indesign file?
Thanks for the quick reply -
What's the code for applying CSS to an XML file, in a dynamic text feild
Hi all,
Very simply put, just like in the title.
If you have a CSS ready, an XML file that already appears
inside a dynamic text field, what AS2 code would you use to connect
the CSS so it applies to the XML file which is now unstyled?
thanks!!!...sorry for thaking a while to get back to you. I pluged the
code you provided and the exported flash does not deplay the text.
instead it says "undefined" which to me means something in the xml
files is work, which is strage since I tested the xml file in a
browser and it works find. so i am providing both the AS code
(below) and the xml and css file (attached). my hope is that you
can direct me to what the problem is.
THANK YOU AGAING FOR ALL YOU HELP!!!
AS code:
Scrolling Text XML by Digital Science |
www.digitalscience.za.org
/////////////Load XML Data/////////////
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
header = [];
txt = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
header
= xmlNode.childNodes.childNodes[0].firstChild.nodeValue;
txt
= xmlNode.childNodes.childNodes[1].firstChild.nodeValue;
gotoAndStop(11);
} else {
errorMsg.text = "Error loading XML";
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("member_content_test.xml");
stop();
import TextField.StyleSheet;
var ss:StyleSheet = new StyleSheet();
ss.onLoad = function() {
txt_mc.styleSheet=this; // where yourTF is your textfield
ss.load("jokes.css"); // where yourSS.css is your css file. -
Loading multiple XML files into one XMLList
I am working on an app where I will load a list of recipes. Each recipe is an XML file. I would have an XML file that lists the filenames that need to be loaded. I am assuming in can use one HTTPService and loop through this list, and set the url and do myService.send() until all the xml files have been loaded and concatenated into one xml list. True?
My main question here is how do I load each XML file and add it to the same XMLList?
Assume each XML file's root tag is <recipe>. I want to create an XMLList with the root <recipes> with each <recipe> as a first child.
Thanks.Why don't you use the Data centric workflows which will help you to deal with multiple XML files as AS objects? Something like this
1. Create a HTTPService using Data menu -> Connect to HTTPService
2. create a operation getRecipe and enter your URL example URL: http://myserver/recipe?name=recipename
3. Use Configure Return Type to tell that this method returns a Recipe class
4. Use DataBinding to bind the result of this to a DataGrid
Call the following in a loop and
recipeName = myRecipes+ // All of your recipe names, Recipe is a ArrayCollecition
Recipe.setAt(i) = Svc1.getRecipe(recipeName);
At the end you would have a Recipe[]
This is one of the ways you could work instead of having a XMLListCollection and use e4x etc. to go through your collection.
Let us know if this helps, or you are looking for something else.
Thanks
-Sunil -
Combining Multiple XML Files into One File
Hey Everyone,
So I am creating a program that takes in a bunch of arrays and stores them into a single xml file. I am finding out that my lag time to add these arrays to an xml file is getting worse with each array I put into it. I am placing over 5000 arrays into this file. This isn't working how I wanted it to so I have decided I will have to make multiple arrays to be able to obtain all of my arrays without having to sit here all day. I would like to have a VI that will take all of these xml files and put them together into one xml file. Does anyone have any ideas how this could be done?
Thanks,
DustinWe need to set a few groundrules for your data:
1. XML, maybe or maybe not LV schema
2. You will be generating multiple tests, in your example file it is always a 2D array with 2 rows and 1 column, is this for real or just an artifact of this example. I was suspecting that you would have multiple length arrays.
3. What is the timescale of your data taking? If I am doing a relatively short, easy to repeat test, I take my chances with failures and gather all the data and write it at the end. If it is a long, difficult measurement I tend to write in intervals (not necessarily every test, but typically every 5-10 minutes).
If your data is fixed size, like the example file, you can append your individual arrays into one large 2D array in a couple of different ways and write the single array to the XML file. This is more compact. If it is not the same size, I was suggesting that you append only the new XML text to the end of the file as you go along. At the end you finish up by writing the closing tag. If there is a problem before that, the XML file is not readable, but easily fixed by simply adding the closing tag. You can even get fancy by keeping track of the offset of the start of the closing tag and start overwriting the new XML+close tag at that point. This means the file is readable even during the intermediate steps, but you are not writing the whole thing.
I can help with an example or two once you specify the data requirements a little more. -
Hi all,
I've got 200+ XDP files that were created by entering data into a LiveCycle PDF form 200+ times and then exporting the data as XDP 200+ times.
Now, I want to view all the data at once (for example, in an Excel Spreadsheet or database) so I can look for trends in the data or come up with a summary (for example, 180 of 200 responses answered Question 1 'Yes'). The form does have some image fields, but I don't need to see or analyse those fields.
I'm a bit of a newbie. Is there an easy way to do this? Thanks!
- JohnI had a similar goal to gather data from a folder full of XDPs into a spreadsheet to track user behaviors, capture commonly entered values, and run reports.
If you are familiar with Python, I highly recommend creating a simple script using Python 2.6 and the elementTree (effbot.org) libraries.
Since I cut my teeth on this project, I found it helpful to break down the script's tasks into individual parts. The material and examples for getting a folder's contents, writing variables in lists, and using elementtree is as terrific as it is scattered in location and diverse in implementation.
1. Grab an xdp in your directory ( for book in path: )
2. Parse the xml by using the elementtree iterator
3. Assign your element's values to variables during iteration
if element.name == 'dataNode':
variable = element.text
4. At the end print your variables with deliminators between each (I used a pipe "|" because commas were commonly used in our forms)
print "%s|%s|%s|%s|%s" % (currentFileName, variable1, variable2, variable3, variable4)
Once you are happy with the data printed out to your console; and each row corresponds to a xdp, stream the output to a file and import that file into Excel in a CSV-style text import (specifying your deliminator during the import process)
so if your script that does the above is called "xdpGrabber.py", run:
$ python xdpGrabber.py >> xdpSpreadSheet.txt
and open xdpSpreadSheet.txt in excel.
There are some gotchas here - repeating nodes can be tricky, and heavily nested or scattered xml structures will add much more complexity to the script. However, if you are only looking for certain fields that always come in the same order when reading the xdps from top to bottom you can get them using simple "if element.name == 'stuff'" references in the order they appear - as elementtree parses from top to bottom.
If this is appealing to you, I suggest you run one of your sample xdps against the example script given here: http://www.xml.com/pub/a/2003/02/12/py-xml.html
I used Python 2.6 and elementtree on a windows XP laptop. I would routinely create spreadsheets from 3000+ xdps, each with 50-100KB of data, in under 15 minutes. I'm guessing the real bottleneck is streaming the output to disk. There isn't much out there that can compete with elementtree for speed reading xml!
If you need some assistance getting started feel free to reply here or message me for an example script.
Good luck!
-Kasey (scriptocratch) -
Import an xml file into adobe designer field using javascript
Adobe javascript experts ,please help me.
I need to load the data from an xml file into a text field in designer
using javascript and then go through each node in the loaded xml and compare that with form fields in designer and if matching fill the value(node's value from the loaded xml) in form fields.
Please give ur suggestions.
Thanks in advance!!!
regards,
sowmyaThanks for the fast response.
I saw your example and specifically the javascript code
xfa.host.importData("filename.xml").
Just by giving this alone how do I access the values in the xml???
Just by giving the above javascript, my value is not getting populated when I see in pdf preview.
But apart from that you have done dataconnection also and binding in all the columns.What is this for??
Could you kindly explain what u r doing step by step??
Thanks again.
regards,
Sowmya -
How to upload an XML file into another system
Hi friends,
I have a requirement where I need to upload an XML file into one system
which has been downloaded using another system.
I have tried using the method ' cl_gui_frontend_services=>gui_upload'
to upload the file but it is going for dump.
I have used the method ' w_xml->import_from_file' also,
but it is also going for dump ,because both methods are using the same FM
' GUI_UPLOAD'.
Can any one suggest on this.
Regards,
Bhargavi.D"Here is the Explaination for uploading the XML Format file to sap " through ABAP Program ....
1. Basically you simply have to convert the XML file into the proper IDoc format. There are many ways to achieve this. One solution would be to convert it externally to SAP, e.g. via VB Script or with an XSLT transformation. Or you use the built in SAP functions for importing an IDoc from an XML stream.
2. Uploading a file is either done via GUI_UPLOAD or via the usual way of reading a file from the application server (Open dataset. Read dataset) But what do you mean by "send to external system"? Do you want to convert an IDoc into XML? Then you simply define an XML port with WE21 to send the IDoc out.
Here is an example of code that loads an XML from file and posts it as an IDoc. Please keep in mind that the XML has to be in its canonical format as described in the interface repository: ifr.sap.com (choose the template of the desired IDoc from there as an example).
data: data_tab type table of char1024.
data: XML_STREAM type string.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'D:test.xml'
* FILETYPE = 'ASC'
* HAS_FIELD_SEPARATOR = ' '
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = DATA_TAB
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'CONVERT_TABLE_TO_STRING'
EXPORTING
I_TABLINE_LENGTH = '1024'
IMPORTING
E_STRING = XML_STREAM
TABLES
IT_TABLE = DATA_TAB[].
write: / xml_stream color col_total.
data: CONTENT_LENGTH type string.
data: CONTENT_TYPE type string.
data: REMOTE_ADDR type string.
CALL FUNCTION 'IDOC_INBOUND_XML_VIA_HTTP'
EXPORTING
XML_STREAM = XML_STREAM
CONTENT_LENGTH = content_type
CONTENT_TYPE = content_type
REMOTE_ADDR = remote_addr
EXCEPTIONS
NO_IDOCS_SAVED = 1
TAG_ERROR = 2
NO_DATA_RECEIVED = 3
NO_IDOCS_RECEIVED = 4
SEGMENT_ERROR = 5
IDOC_WAS_SEND_SECOND_TIME = 6
OTHERS = 7
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
write: / sy-subrc color COL_NEGATIVE.
ENDIF.
reward points if it is usefull.......
Girish -
hello everyone,
can i know is it posible to combine 2 xml file into one xml file?
if possible
can i know how?
thank you
: )Of course you have to make up some specifications to deal with the requirements forced by XML files. For example: an XML file must have a single root element, so you can't just concatenate the two input files. So your specifications have to say whether the root element of the result is a new element, containing two children which are the original input documents, or something else.
-
Linking a class to a dynamic text field to load XML data.
Hi,
I'm quite new to ActionScript and would be grateful for any help here.
I want to load text into a dynamic text field (called 'about_tab') using a class depending on the language selected (by clicking on a flag icon) by the user.
I managed to get this to work when the ActionScript was written directly in the timeline, but am having problems with doing the same thing via a class.
This is my class file:
package
import flash.display.SimpleButton;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
public class ChangeLang extends SimpleButton
public function ChangeLang()
addEventListener(MouseEvent.CLICK, switchLang);
trace("ChangeLang class working");
public function switchLang(event:MouseEvent):void
var lang = event.target.name;
var req:URLRequest = new URLRequest("languages/"+lang+".xml");
var loader:URLLoader = new URLLoader();
var substance:XML;
function xmlLoaded(event:Event):void
trace("function xmlLoaded is running");
substance = new XML(loader.data);
about_tab.text = substance.about_lbl;
loader.addEventListener(Event.COMPLETE, xmlLoaded);
loader.load(req);
Here's one of my XML files (the other is the same except "About" is written in German):
<substance>
<about_lbl>About</about_lbl>
</substance>
When I run it, it returns my trace statements that the class ChangeLang and the function xmlLoaded are running, but no text appears in the dynamic text field (I should/want to see the word 'About'). I get this error message:
1120: Access of undefined property about_tab
The problem, I'm guessing, is in the part in red in my code. I think I need to target the text field in the display list by creating a reference to it. If so, could someonw point out how I do this, or perhaps a tutorial that would help. I've tried adding the word stage (i.e.,stage.about_tab.text = substance.about_lbl; ) but it still doesn't connect. I guess there's something really simple I'm missing, so I apologize if this comes across as a stupid question
Thanks for any help.Hello flashrocket!
I'm also new to AS3 and I've just started using external classes and I think I know what you should do to put your code to work.
Instead of using the text field you created inside your flash file, why don't you use the "TextField" class to create an instance of this object? It's the exact same thing as when you create and instantiate a new text field inside Flash.
First, import flash.text.*; (includes classes like TextField, TextFieldAutoSize, TextFormat, TextFormatAlign, etc)
Than you just have to create a var like
public var about_tab : TextField;
or
public var about_tab : TextField = new TextField();
then, to adjust the properties of this tab you use dotsyntax as if it where on your stage like:
about_tab.x = 50; about_tab.alpha = .5; etc...
you can even create a function to "config your textField"
private function createAndConfigTextField() : void {
about_tab = new TextField(); //you only need this line if you
// only typed something like "public var about_tab:TextField;
// if instead you used "public var about_tab:TextField = new TextField(); outside
// this function, just skip this first line because you already have an instance of
// text field named "about_tab"...
about_tab.autoSize = TextFieldAutoSize.CENTER;
about_tab.background = true;
about_tab.border = true;
var aboutTextFormat : TextFormat = new TextFormat();
format.font = "Arial";
format.color = 0x000000;
format.size = 11;
format.bold = true;
format.align = TextFormatAlign.CENTER;
about_tab.defaultTextFormat = aboutTextFormat;
addChild(about_tab);
This is just an example of what you can do... I hope you get it... let me know if you have any doubt... -
Put PHP Content into Dynamic Text Field
How do I put the contents of a php document into a dynamic
text field in a Flash document? Thanks.
GDo you mean an html document generated from a PHP script?
Do you mean the source of a PHP script?
Probably you mean you want to format a page such as a PHP
script would do.
That is done either manually inside a Flash movie or
dynamically via
Actionscripting. Then you only send data back and forth
between PHP and
Flash using either the LoadVars or the XML Actionscript
classes. You can use
HTML inside of Flash TextField objects but again that will be
data sent from
the PHP server script.
Here are some basic examples I use in Flash seminars you can
look at:
http://www.hosfordusa.com/ClickSystems/courses/flash/examples/LoadVars/LoadVarsEx01.php
http://www.hosfordusa.com/ClickSystems/courses/flash/examples/LoadVars/Ex02/LoadVarsEx02.p hp
http://www.hosfordusa.com/ClickSystems/courses/flash/examples/GenerateFlashObjectsFromPHP/ Ex01/GenerateFlashObjectsFromPHPEx01_Doc.php
http://www.hosfordusa.com/ClickSystems/courses/flash/examples/XMLPHP/EX01/XMLPHPEchoEx01_D oc.php
You also want to look at the docs for LoadVars and XML
sendAndLoad methods:
XML
http://livedocs.macromedia.com/flash/8/main/00002879.html
LoadVars
http://livedocs.macromedia.com/flash/8/main/00002336.html
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
"gena.wenli" <[email protected]> wrote in
message
news:e5g6av$lpv$[email protected]..
How do I put the contents of a php document into a dynamic
text field in a
Flash document? Thanks.
G
Maybe you are looking for
-
I have a Fieldpoint system connected via a FP-1600 ethernet module to our local network. I can use CWDataSocket with Visual Basic 6 (under WinNT 4) to communicate with the fieldpoint hardware via the fieldpoint explorer and OPC server. But if I try t
-
Is anyone else having difficulties using a HD to back up their MacBook Pro? I recently upgraded to Mountain Lion and now the Time Machine fails to back up after previously working fine under Snow Leopard?
-
Creative Sound Blaster Audigy Platinum
Im having issues with this card when I bought it it was great but now after reformats and installing from the software disc I frist recieve an error saying it cant find the remote reciever then I recieve an exclamation mark next to the audio media co
-
Hey there, I Have an iMac 21,5" 8GB RAM 1024MB 2,9Ghz. I buyed it in Feburary. I want to play Call of Duty Ghosts on my iMac i use Win7 with Parallels. I don't know if it works? I already have Skyrim and Fifa 14 and they work very well. So I want to
-
My ibook works fine. That is the hard drive boots up and I can hear the system work. When I Plug it into an external display I can see the desktop and all the applications work. I do, however cannot see anything but a white/grey screen on the built-i