Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a menu inside a MC

Status
Not open for further replies.

webscriptprogrammer

Programmer
Nov 26, 2005
31
SE
Hi

I have a MC name mcCat
I like to create a menu inside that MC

I have a XML file that read in a other MC so I like to take some info from that and put that inside the mcCat and create a menu

Right now I have a list and that is not so nice

Right now I have
Code:
_parent._parent.listcat.addItem(currentCategory);

I start to make it basic so now link yet only text but that dont work

This is a code I have found

Code:
for(i=0; i<20; i++){
   t = this.attachMovie("mcCat", "clip"+i, this.getNextHighestDepth(), {_x:200, _y:10+(i*10)});
   t.Title.text ="Testing testing"+i
}

The text loop outside the scrollpane (I use scrollpane to control mcCat)

I have mcCat in "export for actionscript" and inside the scrollpane I have contentPath too "mcCat"

 
Well, without seeing much of your code, its hard to tell what exactly the problem is. It may be as simple as needing to redraw the content window and/or the scrollpane. Use the invalidate() function.

Code:
for(i=0; i<20; i++){
   t = this.attachMovie("mcCat", "clip"+i, this.getNextHighestDepth(), {_x:200, _y:10+(i*10)});
   t.Title.text ="Testing testing"+i
   this.invalidate();
}

If that doesn't work, make sure you're actually making the movie clip correctly. I'd try using _root.attachMovie in you code above and make sure its at least attaching corretly.

-Dustin
Rom 8:28
 
Hi

Here is the code
Code:
var vlist:XML = new XML();
vlist.ignoreWhite = true;

vlist.onLoad = function() {
	var portfolio:Array = this.firstChild.childNodes;
	for(i=0;i<portfolio.length;i++) {
		
		if(portfolio[i].attributes.cat!=category)
		{
		t = this.attachMovie("mcCat", "clip"+i, this.getNextHighestDepth(), {_x:200, _y:10+(i*10)});
		t.Title.text = portfolio[i].attributes.cat;
		category = portfolio[i].attributes.cat;
		trace(portfolio[i].attributes.cat);
		}
	}
}
	
var vidList:Object = new Object();

vlist.load("myData.xml");

nothing show

I have a very basic XML right now

Code:
<portfolio>
	<item cat="Category 1" id="1" />
	<item cat="Category 1" id="3" />
	<item cat="Category 2" id="4" />
	<item cat="Category 3" id="5" />
	<item cat="Category 3" id="6" />
	<item cat="Category 4" id="1" />
	<item cat="Category 4" id="4" />
	<item cat="Category 5" id="6" />
	<item cat="Category 5" id="7" />
	<item cat="Category 5" id="8" />
	<item cat="Category 5" id="9" />
</portfolio>
 
First of all, I'd try tracing before your if statement. Makesure you're getting portfolio.attributes.cat or else it will always be undefined!=undefined and it will never run.

Another problem I see would be that you are calling attachMovie() from and XML class. That won't do you any good since there is no visual element.

I generally make myself a class that will conatian my xml file and a reference to my container. Inside that class I use the delegate function to parse my loaded xml. Here's one of mine:

Code:
import mx.utils.Delegate;
class ArticleLoader {
	var Container:MovieClip;
	var Articles:Array;
	var aXML:XML;
	
	function ArticleLoader() {
		this.Articles = new Array();
	}
	
	function loadXML(strXMLFile:String) {
		this.aXML = new XML();
		this.aXML.ignoreWhite = true;
		//Delegate will set the scope of the xml file to this movie so we can reference local variables.
		this.aXML.onLoad = Delegate.create(this, importArticles);
		this.aXML.load(strXMLFile);
	}
	
	function importArticles() {
		var i:Number;
		var n:Number;
		var myXMLNode:XMLNode = this.aXML.firstChild;
		var myArticle;
		for(i=0;i<myXMLNode.childNodes.length;i++) {
			myArticle = new Article();
			myArticle.eventType = myXMLNode.childNodes[i].attributes.type;
			for(n=0;n<myXMLNode.childNodes[i].childNodes.length;n++) {
				switch(myXMLNode.childNodes[i].childNodes[n].nodeName) {
					case "postDate" :
						myArticle.PostDate = myXMLNode.childNodes[i].childNodes[n].firstChild.nodeValue;
						break;
					case "title" :
						myArticle.Title = myXMLNode.childNodes[i].childNodes[n].firstChild.nodeValue;
						break;
					case "shortTitle" :
						myArticle.ShortTitle = myXMLNode.childNodes[i].childNodes[n].firstChild.nodeValue;
						break;
					case "story" :
						myArticle.Story = myXMLNode.childNodes[i].childNodes[n].firstChild.nodeValue;
						break;
					case "imageURL" :
						myArticle.ImageURL = myXMLNode.childNodes[i].childNodes[n].firstChild.nodeValue;
						break;
				}
			}
			this.Articles.push(myArticle);
			this.Container.ArticleNav.AddButton(this.Articles.length-1);
		}
		this.loadArticle(0);
	}
        
        function loadArticle(id) {
		this.Container.txtTitle.text = this.Articles[id].Title;
		this.Container.mcScrollWin.txtTextBox.text = this.Articles[id].PostDate + "\n" + this.Articles[id].Story;
		this.Container.scrollToTop();
		this.Container.PicContainer.LoadPic(this.Articles[id].ImageURL);
	}
}

I'm not using a scrollpane in this example.. instead i'm using my own scroller. However, you should be able to use the same method. I'll attach my scroller code too so you can see how the AddButton() function works.

Code:
class ArticleSlider extends MovieClip {
	var Buttons:Array;
	var CurrentX:Number;
	var ButtonWidth:Number = 115;
	var OriginalX:Number;
	var SlideToX:Number;
	var CurrentOffset:Number;
	
	function ArticleSlider() {
		this._parent.slideLeftBtn._visible = false;
		this._parent.slideRightBtn._visible = false;
		this.Buttons = new Array();
		this.CurrentOffset = 0;
		this.CurrentX = 3;
		this.OriginalX = this._x;
	}
	
	function AddButton(ArtNum:Number) {
		var myBtn = new ArticleButton;
		myBtn._x = this.CurrentX;
		myBtn._y = 15;
		this.CurrentX += 115;
		myBtn = this.attachMovie("ArticleButton","ArtBtn"+ArtNum,this.getNextHighestDepth(),myBtn);
		myBtn.setArticle(ArtNum);
		this.Buttons.push(myBtn);
		if(this.Buttons.length > 4 && this._parent.slideRightBtn._visible == false) {
			this._parent.slideRightBtn._visible = true;
		}
	}
	
	function slide(numPositions) {
		this.CurrentOffset += numPositions;
		trace(this._parent.slideLeftBtn._visible);
		if(this.CurrentOffset == 0) {
			this._parent.slideLeftBtn._visible = false;
		} else {
			this._parent.slideLeftBtn._visible = true;
		}
		trace(this.Buttons.length + " > " + 4 + " && " + this.Buttons.length + " - " + this.CurrentOffset + " == 4");
		if(this.Buttons.length > 4 && this.Buttons.length - this.CurrentOffset == 4) {
			this._parent.slideRightBtn._visible = false;
		} else {
			this._parent.slideRightBtn._visible = true;
		}
		this.SlideToX = this.OriginalX - (this.CurrentOffset * this.ButtonWidth);
		this.onEnterFrame = function() {
			if(this._x <> this.SlideToX) {
				var numToChange:Number = (this.SlideToX - this._x)/3; 
				if(numToChange > 0) {
					numToChange = Math.ceil(numToChange);
				} else {
					numToChange = Math.floor(numToChange);
				}
				this._x += numToChange;
			} else {
				trace("Deleteing OEF");
				delete this.onEnterFrame;
			}
		}
	}
}

-Dustin
Rom 8:28
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top