PDA

View Full Version : How to create textfield and movieclip automatically



sathishgforum
September 23rd, 2003, 03:19 AM
Hi Friends

Howz the day? Well im new to Flash scripting. Can you guide me for the following problem.I generated the xml file through that data in it, i would like to get the output in flash file (.fla).

Hereby i shown you sample xml file in simple format
--------------------------------------------------------
<?xml version="1.0" ?>
<Catalog Name="Guiness Records">
<Page index="1">
<Object type="Content" xpos="200" ypos="200" objwidth="300" objheight="50">
This is a Test Document
</Object>
<Object type="Image" xpos="170" ypos="270" objwidth="300" objheight="50">
album.jpg
</Object>
</Page>
</Catalog>
--------------------------------------------------------

Where in this xml file number of object type of content and image are not same for every page.For every content like to create <TextField> as well as every image like to create <Movieclip> automatically based on every page.

After generating the objects in the xml file into the flash scripting.If its more than one page.User can able to view in the format of <NEXT> and <PREVIOUS> button.

So this is the scenario.if anyone come across this problem just tell your way of suggestion,snippets or sample peice of code to move ahead further.

Any kind of help in this issue can be highly appreciated.Have a nice day

Regards
SATHISH KUMAR G

ajok
September 23rd, 2003, 08:17 AM
dear sathish,

i hope that u want to make a slide show from external data; here is the stuff u asked (process xml and dynamically create textfeild and movieClip) .

first take a look of xml file

==============================================

<?xml version="1.0" ?>
<catalog name="records">
<page index="1">
<object type="content" xpos="200" ypos="200" height="50" width="200">good this is a test</object>
<object type="Image" xpos="200" ypos="200" height="50" width="200">1.jpg</object>
</page>
<page index="2">
<object type="content" xpos="200" ypos="200" height="50" width="200">this is a test</object>
<object type="Image" xpos="200" ypos="200" height="50" width="200">2.jpg</object>
</page>
</catalog>

==============================================

now see the flash code for load and preocess xml

data = [];
my_xml = new XML();
my_xml.load("test.xml");
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success) {
if (success) {
for (j=0; j<my_xml.childNodes[0].childNodes.length; j++) {
page = [];
for (i=0; i<my_xml.childNodes[0].childNodes[j].childNodes.length; i++) {
myObject = new Object();
for (var k in this.childNodes[0].childNodes[j].childNodes[i].attributes) {
myObject[k] = this.childNodes[0].childNodes[j].childNodes[i].attributes[K];
}
myObject.value = this.childNodes[0].childNodes[j].childNodes[i].lastChild;
page[i] = myObject;
}
data[j] = page;
}
makePages();
delete (my_xml);
// dispose xml object loaded
} else {
trace("error in loading data");
}
};

here i am storing all data to and multidim array, as objects actually it is not necessary you can directly do things when it loads. but i am storing the data and disposing the xml object, coz maybe for furter intraction it is needed !!! its my style ... :) always look for furthere dynamisum

find here for remaing code for create textfield and movie clip

function makePages() {
for(i=0;i<data.length;i++){
_root.createEmptyMovieClip("page" add i,i+1)
for(j=0;j<data[i].length;j++){
_root["page" add i].createEmptyMovieClip("page" add j,j+1)
if(data[i][j].type=="content"){
_root["page" add i].createTextField("myText",10,data[i][j].xpos,data[i][j].ypos,data[i][j].width,data[i][j].height)
_root["page" add i].myText.text=data[i][j].value
_root["page" add i].myText.textColor=0xFF0000
}else{
loadMovie(data[i][j].value,_root["page" add i]["page" add j])
_root["page" add i add ".page" add j]._x=data[i][j].xpos
_root["page" add i add ".page" add j]._y=data[i][j].ypos
_root["page" add i add ".page" add j]._height=data[i][j].height
_root["page" add i add ".page" add j]._width=data[i][j].width
}
}
_root["page" add i]._x=Stage.width/4
_root["page" add i]._y=Stage.width/4
}

}

note that this is not complite code for slide show all the pic which is loading will be visible at the screen, i hope you can do the remaining script for hiding the visibility and navigation as it is eassy.

incase more doubt please feel free to ask me

regards,

Ajo.K.Jose
ajok@indiatimes.com