Need help with creating buttons and content dynamically

AS, xml driven navigation menu and content

Page 1 of 1

1 Replies - 650 Views - Last Post: 25 January 2010 - 06:08 PM

#1 silvermario  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-January 10

Need help with creating buttons and content dynamically

Post icon  Posted 22 January 2010 - 09:04 AM

Hi, i'm developing a website for my client. Here is the test version http://www.net-plus....t/denis/strona/
The page Partnerzy (Partners) will look like this:

http://www.net-plus....ash-problem.jpg

There will be a menu created dynamically from a XML file, after clicking a menu button a MovieClip with a photo and category description will show up.
After clicking the button "View more" the MovieClip with description will be removed and MovieClips with category products will show up through a for-loop on XML products nodes from this category.

The XML will look like this:
<category name="torty" url="torty.jpg" description="Category description">
	<item name="Tiramisu" make="Balconi" url="tiramisu.jpg"><![CDATA[Product description...]]></item>
	<item name="Cake" make="Balconi" url="cake.jpg"><![CDATA[Product description...]]></item>
</category>
<category name="ciastka" url="ciastka.jpg" description="Category description">
	<item name="Tiramisu" make="Asolo Dolce" url="tiramisu.jpg"><![CDATA[Product description...]]></item>
	<item name="Cake" make="Asolo Dolce" url="cake.jpg"><![CDATA[Product description...]]></item>
</category>


I can create the navigation menu, and maybe i will manage to create first MovieClip with the category photo and description but i don't have any idea how to create those next MovieClips with products desciption after clicking the button "View more".

I don't ask you for complete code and explanation how to do this.
I'm begging you for hints how to start and how should i get on with this.
Maybe somebody have seen some tutorials or topics on forums that will help me with this job? The please drop me a link.

I'm trying right now to mess with code from this tutorial http://flashexplaine...ery-in-flash-8/ , but for a beginner it's not so easy.
When i will have some working code to show i will write it here, but as for now please help me :(

EDIT:
I'm developping in ActionScript 2.0

This post has been edited by silvermario: 22 January 2010 - 09:06 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Need help with creating buttons and content dynamically

#2 silvermario  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-January 10

Re: Need help with creating buttons and content dynamically

Posted 25 January 2010 - 06:08 PM

Hi, i googled and google a lot and there is a slow progress in my actionscript coding :)

Maybe now somebody could help me

I dropped the idea of showing a category description page with a button "view more" to show all products that are in this category for making it easier for me.

Now i have this xml:
<produkty folderUrl="produkty/">   
				<category name="Torty" url="torty.jpg" description="Opis kategorii">
					<product name="Tiramisu" make="Balconi" url="tiramisu.jpg"><![CDATA[Product description...]]></product>
					<product name="Cake" make="Balconi" url="cake.jpg"><![CDATA[Product description...]]></product>
					<product name="Cake" make="Balconi" url="cake.jpg"><![CDATA[Product description...]]></product>
					<product name="Cake" make="Balconi" url="cake.jpg"><![CDATA[Product description...]]></product>
				</category>
				<category name="Ciastka" url="ciastka.jpg" description="Opis kategorii">
					<product name="Tiramisu" make="Asolo Dolce" url="tiramisu.jpg"><![CDATA[Product description...]]></product>
					<product name="Cake" make="Asolo Dolce" url="cake.jpg"><![CDATA[Product description...]]></product>
				</category>
				<category name="Batony" url="ciastka.jpg" description="Opis kategorii">
					<product name="Tiramisu" make="Asolo Dolce" url="tiramisu.jpg"><![CDATA[Product description...]]></product>
					<product name="Cake" make="Asolo Dolce" url="cake.jpg"><![CDATA[Product description...]]></product>
				</category>
				<category name="Ciasta francuskie" url="ciastka.jpg" description="Opis kategorii">
					<product name="Tiramisu" make="Asolo Dolce" url="tiramisu.jpg"><![CDATA[Product description...]]></product>
					<product name="Cake" make="Asolo Dolce" url="cake.jpg"><![CDATA[Product description...]]></product>
				</category>
				<category name="Pieczywo" url="ciastka.jpg" description="Opis kategorii">
					<product name="Tiramisu" make="Asolo Dolce" url="tiramisu.jpg"><![CDATA[Product description...]]></product>
					<product name="Cake" make="Asolo Dolce" url="cake.jpg"><![CDATA[Product description...]]></product>
				</category>
				<category name="Przekąski" url="ciastka.jpg" description="Opis kategorii">
					<product name="Tiramisu" make="Asolo Dolce" url="tiramisu.jpg"><![CDATA[Product description...]]></product>
					<product name="Cake" make="Asolo Dolce" url="cake.jpg"><![CDATA[Product description...]]></product>
				</category>
				<category name="Produkty sezonowe" url="ciastka.jpg" description="Opis kategorii">
					<product name="Tiramisu" make="Asolo Dolce" url="tiramisu.jpg"><![CDATA[Product description...]]></product>
					<product name="Cake" make="Asolo Dolce" url="cake.jpg"><![CDATA[Product description...]]></product>
				</category>
				<category name="Inne" url="ciastka.jpg" description="Opis kategorii">
					<product name="Tiramisu" make="Asolo Dolce" url="tiramisu.jpg"><![CDATA[Product description...]]></product>
					<product name="Cake" make="Asolo Dolce" url="cake.jpg"><![CDATA[Product description...]]></product>
				</category>
			</produkty>


and the actionscript:

var Produkty = _root.parsed_obj.section[2].page[3].produkty[0];

ProductsHolder_mc._x = buttonHolder_mc._x + 200;
ProductsHolder_mc._y = buttonHolder_mc._y;


var loader:MovieClipLoader = new MovieClipLoader();


function loadButtons() {
	for (i=0; i<Produkty.category.length; i++) {
		//trace(Produkty.category[i]);

		imageFolder = Produkty.folderUrl;
		categoryImage = _root.rootPath+imageFolder+Produkty.category[i].name;
		categoryText = Produkty.category[i].name;
		newBut = buttonHolder_mc.attachMovie("but template", "but"+i, buttonHolder_mc.getNextHighestDepth());
		newBut.butName_mc.name_txt.text = categoryText;
		newBut.butName_mc.name_txt.autoSize = "left";
		newHeight = i * 21;
		newBut._y = newHeight;
	   
		loader.loadClip(dostawcaImage, target);
		newBut.category = Produkty.category[i];
	   
		buttonclicked();
	   
	}
}

function buttonclicked():Void {
   
	newBut.onRelease = function() {
	   
				// how to find button instances??
		for (i=0; i<Produkty.category.length; i++) {
			newBut["but"+i].gotoAndStop(1);
			trace(_parent[but1]);
			trace(this[but1]);
			trace(but1);
			trace(newBut["but1"]);
			trace(["but"+i]);
		}
	   
				// change button background
		this.gotoAndStop(2);	   
	   
		//ProductsHolder_mc.unloadMovie();
					   
		for (i=0; i<this.category.product.length; i++) {
			trace(this.category.product[i]);
			NewProductItem = ProductsHolder_mc.attachMovie("ProductItem", "product"+i, ProductsHolder_mc.getNextHighestDepth());
			NewProductItem._y = (i * 150);
		   
			// code importing nodes info to movieclips
		   
				// just for testing unloadMovie function
			NewProductItem.onRelease = function() {
				ProductsHolder_mc.unloadMovie();
			}
		}
					   
	}
}

loadButtons();


Buttons are dynamically created in an empty mc called buttonHolder_mc
After clicking a button the text from the xml nodes of a chosen category ( xml is parsed through this parser blog.greensock.com/xmlparseras2/ ) is being loaded into an empty mc called ProductsHolder_mc.

The newBut instance of "but template" movieclip has 2 frames with different backgrounds, after clicking a button it should change background. But after i click another button it changes background too and the first button stays the same. I tried to loop through all button instances and make them go to first frame but i have no idea how to address them ( as you can see in my code i tried everything to find even one button but i failed ).

My second problem is how to unload the ProductsHolder_mc after clicking another button. I can remove all movieclips from it after clicking a NewProductItem but how can i remove all movieclips from the ProductsHolder_mc after clicking another newBut instance?

EDIT:
problem no 1 solved with this snippet of code
newBut.onRelease = function() {
		//trace(this.category);
		for (i=0; i<Produkty.category.length; i++) {		   
			buttonHolder_mc["but" + i].gotoAndStop(1);
			trace(buttonHolder_mc["but" + i]);		   
		}
		this.gotoAndStop(2);


This post has been edited by silvermario: 25 January 2010 - 06:47 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1