A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: MC creation

  1. #1
    Junior Member
    Join Date
    Jan 2006
    Posts
    6

    MC creation

    Hi,

    I'm on a journey to make a website entirely made inside of one empty frame of actionscript. Very early I have hit a snag, I'm using AS2 by the way. I load info from an xml, inside the xml looks like this.

    <xml>
    <home></home>
    <history></history>
    <portfolio></portfolio>
    <contact></contact>
    </xml>

    then my script on the first page looks like this:

    var loader = new XML();
    loader.ignoreWhite = true;
    loader.onLoad = function(success) {
    if (success) {
    xml = loader.firstChild;
    trace("success");
    menue();
    }
    };
    loader.load("data.xml");

    //Control Variables
    menueItemX = 0;

    menuePadding = 10;
    //Create Menu Container
    var menucontain = _root.createEmptyMovieClip("menucontainer",this.ge tNextHighestDepth());
    //Create menue
    menue = function () {
    for (i=0; i<xml.childNodes.length; i++){
    //Create item container
    var menue = menucontain.createEmptyMovieClip("item"+[i], this.getNextHighestDepth());
    //Create textField in container and set properties
    menue.createTextField("my_txt", 1, 0, 0, 0, 0);
    menue.my_txt.autoSize = "center";
    menue.my_txt.multiline = false;
    menue.my_txt.wordWrap = true;
    menue.my_txt.selectable = false;
    //menue.my_txt.embedFonts = true;
    var my_fmt:TextFormat = new TextFormat();
    my_fmt.color = 0xFFFFFF;
    my_fmt.size = 30;
    my_fmt.bold = true;
    //my_fmt.font = "Arial";
    //Write text from xml into menue item
    menue.my_txt.text = xml.childNodes[i].nodeName;
    //Apply text formatting
    menue.my_txt.setTextFormat(my_fmt);
    menue._x = menueItemX;
    menueItemX += menue.my_txt.textWidth+menuePadding;
    trace(menue.my_txt.textWidth);
    menue.my_txt._width = menue.my_txt.textWidth + 5;
    menue.my_txt._height = menue.my_txt.textHeight;
    //release actions of button
    menue.onRelease = function(){
    trace(this.my_txt.text);
    }
    //rollover actions of button
    menue.onRollOver = function(){
    this._alpha = 50;
    }
    menue.onRollOut = function(){
    this._alpha = 100;
    }
    //trace
    trace(xml.childNodes[i].nodeName);
    }
    };

    It's pretty long and does a lot and worked fine until I wanted to make every created mc go inside a menucontain mc. What happens is only the last item of the xml gets written. if I try this code it works great:

    var loader = new XML();
    loader.ignoreWhite = true;
    loader.onLoad = function(success) {
    if (success) {
    xml = loader.firstChild;
    trace("success");
    menue();
    }
    };
    loader.load("data.xml");

    //Control Variables
    menueItemX = 0;

    menuePadding = 10;

    //Create menue
    menue = function () {
    for (i=0; i<xml.childNodes.length; i++){
    //Create item container
    var menue = this.createEmptyMovieClip("item"+[i], this.getNextHighestDepth());
    //Create textField in container and set properties
    menue.createTextField("my_txt", 1, 0, 0, 0, 0);
    menue.my_txt.autoSize = "center";
    menue.my_txt.multiline = false;
    menue.my_txt.wordWrap = true;
    menue.my_txt.selectable = false;
    //menue.my_txt.embedFonts = true;
    var my_fmt:TextFormat = new TextFormat();
    my_fmt.color = 0xFFFFFF;
    my_fmt.size = 30;
    my_fmt.bold = true;
    //my_fmt.font = "Arial";
    //Write text from xml into menue item
    menue.my_txt.text = xml.childNodes[i].nodeName;
    //Apply text formatting
    menue.my_txt.setTextFormat(my_fmt);
    menue._x = menueItemX;
    menueItemX += menue.my_txt.textWidth+menuePadding;
    trace(menue.my_txt.textWidth);
    menue.my_txt._width = menue.my_txt.textWidth + 5;
    menue.my_txt._height = menue.my_txt.textHeight;
    //release actions of button
    menue.onRelease = function(){
    trace(this.my_txt.text);
    }
    //rollover actions of button
    menue.onRollOver = function(){
    this._alpha = 50;
    }
    menue.onRollOut = function(){
    this._alpha = 100;
    }
    //trace
    trace(xml.childNodes[i].nodeName);
    }
    };

    but then all the menu items created exist on the root, but I want them in another mc, to be able to change the position of the entire menu at any time... Can anyone offer me some guidance as to what I'm doing wrong?
    Thanks so much for your help

  2. #2
    Senile member! :)
    Join Date
    Dec 2001
    Location
    Saunaswamp (transl)
    Posts
    2,296
    When you create your movieclips inside that "menucontain" movieclip I assume you change the path used on createEmptyMovieClip. Just remember to change the path on the getNextHighestDepth() too.

    /Mirandir

  3. #3
    Junior Member
    Join Date
    Jan 2006
    Posts
    6
    great call, that totally cought me off guard. I'll keep that in mind in the future...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center