-
Client Software Programmer
[RESOLVED] xml + flash as2 help, I can buy you a drink ;)
Hi can someone make me an example of xml data being used with flash. I would like an example of xml attaching a movieclip on a certain x and y of a flash stage,
I'm making an 8bit rpg, this will be used to load certain parts of my flash maps (location with a bunch of movieclips). So also if its not too much trouble I would also like to be able to trigger different xml files to load and unload certain locations. (you can use a flash button to do this and i'll work from there im not dumb).
Thanks, I have paypal just a couple bucks on it so I can buy a drink for who ever helps me just a little kindness on my part.
-
I can make an example. Why aren't you in AS3?
-
Client Software Programmer
Cause I love as2 and I am sticking with it no matter what limitations I get, and thanks moot.
-
Designer, Programmer, Musician
Ha ha ha ha, i would say the same thing that moot said "why you don't move to AS3". I am already working with XML, i can load data from it to flash with nodes and for loops and stuff. I have to see if I can make the same thing in AS2. But what you are requiring it's easy to achieve. I guess, you put in the .xml the dimensions and the size of the movieclip, and in flash, you make the attachMovie script, but with the variables of x, y, width and height, loaded from the XML, right?
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Client Software Programmer
no me gusta as3 :P I code better on as2
-
Designer, Programmer, Musician
I don't like AS3 neither , but It allows me to do more things than as2. Althought, thinking about it, it's cool because you use LISTENERS for almost everything, and all the elements are placed with addChild on the stage. I was like you before, refusing to jump to AS3...but now that i jumped, I don't regret xD
I can't still keep learing AS2 stuff that i don't know, so i'm working with both languages at the same time.
You want to put the dimensions and location of the movieclip on the XML right?
Like:
<XML>
<movieclip width = 190 height = 244 _x = 23 _y = 444>
</movieclip >
</XML>
And then in the flash call these variables from the XML file, to creat the movieclip with attachMovie in flash, right?
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Client Software Programmer
I dont want to set height/width unless i have too for xml,
each tile is 30x30 I want to create lets say a little area with these 30x30 tiles(movieclips) and on the swf you should have 2 buttons lets say 1 button says load xmlfile1.xml and that xml file will tell flash how the map is built. lets say I click a button that says load xmlfile2.xml than that array of movieclips will be loaded into the game, you should also be able to unload certain xml files so that the game doesnt get laggy, imm going to unload when certain maps arent in use. its going to be a multiplayer game so it will be vast and made up of lots of xml files
-
Designer, Programmer, Musician
Well that's easy, you can first make the Map tiles array and test it in flash. When you have it how you like it, then just put the array in the .xml , and load it with the button press. The map tiles array it's easy to achived, like
map = [0, 1, 0, 0, 2, 0, 0
0, 1 0, 0, 0, 0, 0
1, 0, 0, 0, 0, 0, 0
1, 0, 0, 0, 0, 0, 0]
And then a for loop to loop throught all the array's items.
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Client Software Programmer
-
Designer, Programmer, Musician
Wait -_-
I already achieved. I loaded the array into flash, and tested the array, and the clips are created accordingly. I just have an issue with the function "myVar.onLoad"
I'm working on it
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Client Software Programmer
sweet thanks
-
Designer, Programmer, Musician
Almost there....just few adjustments
I'm ended using XML. It's better because I'm using many variables, tileHeight, tileWidth, vTile, hTile, maps.
AS2
PHP Code:
var num:Number;
var maps:Array = [];
mapBtn1.onPress = function()
{
importMap(0);
}
mapBtn2.onPress = function()
{
importMap(1);
}
mapBtn3.onPress = function()
{
importMap(2);
}
function importMap(num)
{
var hTiles:Number;
var vTiles:Number;
var maps:Array = [];
var tilesWidth:Number;
var tilesHeight:Number;
var myXML:XML = new XML();
myXML.ignoreWhite=true;
myXML.load("maps.xml");
myXML.onLoad = function(success){
if (success){
tileWidth = myXML.childNodes[num].attributes.tileWidth;
tileHeight = myXML.childNodes[num].attributes.tileHeight;
maps.push(myXML.childNodes[num].firstChild.attributes.array.split(","));
hTiles = myXML.childNodes[num].attributes.hTiles;
vTiles = myXML.childNodes[num].attributes.vTiles;
trace(typeof maps[0][0]);
trace("Width: "+tileWidth+" Height: "+tileHeight+" Array: "+maps+" Vertical: "+vTiles+" Horizontal: "+hTiles);
createMap(hTiles, vTiles, maps, tileWidth, tileHeight);
}
}
}
function createMap(hTiles, vTiles, maps, tileWidth, tileHeight)
{
var hspace:Number = 0;
var vspace:Number = 0;
var container:MovieClip;
for(var t in this) {
if(typeof(this[t])=="movieclip" && this[t]._name =="t"+t) {
// if you're clips are not dynamically attached, then de-comment this line:
//holder[i].swapDepths(10000);
this[t].removeMovieClip();
}
}
for (var i:Number = 0; i < hTiles; i++)
{
for (var j:Number = 0; j < vTiles; j++)
{
container = attachMovie("tile", "tile", this.getNextHighestDepth());
container._width = tileWidth;
container._height = tileHeight;
container.gotoAndStop(maps[0][Number(container.getDepth())]);
container._x = hspace+(container._width + hspace)*j;
container._y = vspace+(container._height + vspace)*i;
container._name = "t" + Number(container.getDepth());
}
}
}
XML
HTML Code:
<?xml version="1.0" encoding="utf-8"?>
<map tileHeight="30" tileWidth ="30" vTiles="6" hTiles="6">
<mapArray
array="1,1,1,1,1,1,1,2,2,2,2,1,1,3,2,2,2,1,1,3,2,2,2,1,1,3,3,2,2,1,
1,1,1,1,1,1" />
</map>
<map tileHeight="30" tileWidth ="30" vTiles="10" hTiles="10">
<mapArray
array="1,1,1,1,1,1,1,2,2,2,2,1,1,2,2,2,2,1,1,2,2,2,2,1,1,2,2,2,2,1,
1,1,1,1,1,1" />
</map>
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Designer, Programmer, Musician
Done
AS2
PHP Code:
var num:Number; var maps:Array = [];
mapBtn1.onPress = function() { importMap(0); }
mapBtn2.onPress = function() { importMap(1); }
mapBtn3.onPress = function() { importMap(2); }
function importMap(num) { var hTiles:Number; var vTiles:Number; var maps:Array = []; var tilesWidth:Number; var tilesHeight:Number; var myXML:XML = new XML(); myXML.ignoreWhite=true; myXML.load("maps.xml"); myXML.onLoad = function(success){ if (success){ tileWidth = myXML.childNodes[num].attributes.tileWidth; tileHeight = myXML.childNodes[num].attributes.tileHeight; maps.push(myXML.childNodes[num].firstChild.attributes.array.split(",")); hTiles = myXML.childNodes[num].attributes.hTiles; vTiles = myXML.childNodes[num].attributes.vTiles; trace(maps[0][0]); trace("Width: "+tileWidth+" Height: "+tileHeight+" Array: "+maps+" Vertical: "+vTiles+" Horizontal: "+hTiles); createMap(hTiles, vTiles, maps, tileWidth, tileHeight); } } }
function createMap(hTiles, vTiles, maps, tileWidth, tileHeight) { var hspace:Number = 0; var vspace:Number = 0; var container:MovieClip; if(t != 0) { for(var k=0; k < 5000; k++) { if(this["t"+k] != null) { this["t"+k].removeMovieClip(); } else { break; } } } var t:Number = 0; for (var i:Number = 0; i < hTiles; i++) { for (var j:Number = 0; j < vTiles; j++) { attachMovie("tile", "tile", this.getNextHighestDepth()); tile._width = tileWidth; tile._height = tileHeight; tile.gotoAndStop(maps[0][Number(t)]); tile._x = hspace+(tile._width + hspace)*j; tile._y = vspace+(tile._height + vspace)*i; tile._name = "t" + t; t++; } } }
XML
HTML Code:
<?xml version="1.0" encoding="utf-8"?>
<map tileHeight="30" tileWidth ="30" vTiles="6" hTiles="6">
<mapArray array="1,1,1,1,1,1,
1,2,2,2,2,1,
1,3,2,2,2,1,
1,3,2,2,2,1,
1,3,3,2,2,1,
1,1,1,1,1,1" />
</map>
<map tileHeight="30" tileWidth ="30" vTiles="8" hTiles="8">
<mapArray array="1,1,1,1,1,1,1,1,
1,2,2,2,2,2,2,1,
1,2,2,2,2,2,3,1,
1,2,2,2,2,2,3,1,
1,2,3,3,3,3,3,1,
1,1,1,1,1,1,1,1" />
</map>
<map tileHeight="30" tileWidth ="30" vTiles="8" hTiles="8">
<mapArray
array="1,1,1,1,1,1,1,2,2,2,2,1,1,2,2,2,2,1,1,2,2,2,2,1,1,2,2,2,2,1,
1,1,1,1,1,1" />
</map>
Flash
3 buttons named "mapBtn1", "mapBtn2", "mapBtn3".
1 movieclip exported for actionscript in the library. That movieclip has 3 frames: 1- black 2- green 3-blue
and a stop(); on the first frame.
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Designer, Programmer, Musician
I had to make a DEGREE in AS2 XML today hahahahhaha but now i understand it and i think i've mastered it.
I think this is what you asked for. Otherwise, please let me know.
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Client Software Programmer
Thanks man I got a lot of homework so I cant test it right now but looks about right after reading the code abit, again thanks for putting in work. <3
Last edited by AS3.0; 01-21-2014 at 10:51 PM.
-
Client Software Programmer
wow man this works like a charm thank you so much if you have a paypal inbox me and I can give you a little something
Last edited by AS3.0; 01-22-2014 at 04:09 PM.
-
Designer, Programmer, Musician
-
Designer, Programmer, Musician
And please mark the thread as Resolved. Any other query you have, you can post it here, or inbox me. ^_^
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Sorry I dropped off this but when I went to do AS2, I discovered the Flash CC hack wasn't working so I can't do AS2. So I kept playing with that instead of answering.
Just get over your AS3ism and start doing AS3. Especially since you're still learning. It's easier than you think.
Here's some example xml code pieces. It shows storing the xml in array of objects which you guys should like.
Code:
var xMain = new XML();
var aMain = new Array();
xMain.ignoreWhite = true;
function doMain(){
trace("main()");
//xmlMain.onLoad = xmlLoaded;
xMain.load();
}
xMain.onLoad = function(success) {
if(success){
trace("xMain.onLoad");
var grabNode = this.firstChild.childNodes[0];
var grabLength = grabNode.childNodes.length;
for(var i=0;i<grabLength;i++){
oTemp = new Object();
oTemp.sItemTitle = grabNode.childNodes[i].firstChild.nodeValue;
oTemp.sItemID = grabNode.childNodes[i].attributes["id"];
oTemp.sItemTitle = grabNode.childNodes[i].firstChild.nodeValue;
aMain.push(oTemp);
}
doLoadItems();
}
}
function doLoadItems(){
trace("doLoadItems()");
for(var i=0; i<aMain.length; i++){
mcItems.mcItem.duplicateMovieClip("mcItem_" + i,100+i);
var oNewItem = mcItems["mcItem_" + i];
oNewItem._y = i * 90;
oNewItem._x = 0;
oNewItem.nowPlaying._visible = false;
oNewItem.tItemTitle.text = aMain[i].sItemTitle;
oNewItem.nItemID = aMain[i].sItemID;
oNewItem.bMain.onPress = doPressThumbButton;
}
}
Last edited by moot; 01-28-2014 at 12:55 AM.
-
Designer, Programmer, Musician
Thanks moot. That's exactly what I did in my script. Check it up above! With the slight difference that it don't need a for loop, because we are gettin one item at a time from the XML. When you press one of the Maps buttons, it loads the corresponding nodes and childs from the XML.
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|