I'm writing a little application to run a course, and the engine creates the
navigation menu putting labels in the button etc...

So, as far as I change things like a dynamic text that's on the stage with
something like

mybutton.itemText.text =
my_xml.childNodes[0].childNodes[index-1].attributes["Label"];

this works, but what If I want to change a variable declared in the button?

I would like to retrieve from an XML the movie I want to load pressing this
particular button, but seems like the scope of the "designed" objects and
the programmed object is a little different, since with

in the button movieclip
************************
var myMovieDelegate:String = new String();
var selectedButton:Boolean = new Boolean();
-------------------------------------------
in the engine Class

mybutton.myMovieDelegate(my_xml.childNodes[0].childNodes[index-1].attributes["MovieToLoad"]);

------------------------------------------

this doesn't works, as doesn't works creating a function in the button to
set the variable like

function setMovieDelegate(movie:String):Void {
    myMovieDelegate = movie;
}

Where's the problem?

I'll add the complete code here

--------------

class courseEngine {
    public var addEventListener:Function;
    public var removeEventListener:Function;
    private var dispatchEvent:Function;

    private var ayudaOpen:Boolean = new Boolean();

    function courseEngine() {
        mx.events.EventDispatcher.initialize(this);
        ayudaOpen = false;
    }

    public function initMenu(drawInIt:MovieClip, my_xml:XML) {
        drawInIt.attachMovie("mcMenuUpBorder", "upBorder",
drawInIt.getNextHighestDepth());
        drawInIt.attachMovie("mcMenuUnit", "menuMC1",
drawInIt.getNextHighestDepth(), {_x:0, _y:13});
        initButton(drawInIt.menuMC1, my_xml, 1);
        for (var i:Number = 2;
i<=my_xml.childNodes[0].attributes["NumberOfItems"]; i++) {
            drawInIt.menuMC1.duplicateMovieClip("menuMC"+i, i);
            var pippo:String = new
String(my_xml.childNodes[0].childNodes[i-1].attributes["Label"]);
            trace(drawInIt["menuMC"+i]);
            _root.drawInIt["menuMC"+i].setMovieDelegate(pippo);
            initButton(drawInIt["menuMC"+i], my_xml, i);
            drawInIt["menuMC"+i]._y =
drawInIt["menuMC"+(i-1)]._y+drawInIt["menuMC"+(i-1)].mcGreenBox._height;
        }
        var u:Number = new
Number(my_xml.childNodes[0].attributes["NumberOfItems"]);
        drawInIt.attachMovie("mcMenuUnderBorder", "downBorder",
drawInIt.getNextHighestDepth(), {_x:0, _y:u*35+13});
        var myDropFilter = new flash.filters.DropShadowFilter();
        var myFilters:Array = drawInIt.filters;
        myFilters.push(myDropFilter);
        drawInIt.filters = myFilters;
    }
    private function initButton(button:MovieClip, my_xml:XML, index:Number)
{
        button.itemText.text =
my_xml.childNodes[0].childNodes[index-1].attributes["Label"];
        if (button.itemText.textHeight<16) {
            button.itemText._y = button.itemText._y+6;
            button.itemText._height = 16;
        }
    }
    public function ayudaIsOpen():Boolean {
        trace("passo da questa funzione");
        return ayudaOpen;
    }
    public function callMe():Void {
        dispatchEvent({type:"hearing", target:this});
    }
    public function closemcMenu(myx:Number, myy:Number, myButtonX:Number,
myMenu:MovieClip, myButton:MovieClip):Void {
        myMenu.slideTo(myx, myy, 0.5, "easeInOutCircular");
        myButton._x = myButtonX;
        ayudaOpen = false;
    }
    public function openmcMenu(myx:Number, myy:Number, myButtonX:Number,
myMenu:MovieClip, myButton:MovieClip):Void {
        myMenu.slideTo(myx, myy, 0.5, "easeInOutCircular");
        myButton._x = myButtonX;
        ayudaOpen = true;
    }
    public function menuDispatcher(butName:String){
        var eventObject:Object = {target:this, type:'pressed'};
        eventObject.buttonPressed = butName;
//eventObject.whereDrawn = cliptoDrawin.square_mc;
     dispatchEvent(eventObject);
    }
}
--------------
code in the first frame

var my_xml:XML = new XML();
var myEngine:courseEngine = new courseEngine();
var oViewListener:Object = new Object();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success) {
    myEngine.initMenu(mcMenuContainer, my_xml);
};
my_xml.load("Menu.xml");

oViewListener.pressed = function(oEvent:Object):Void  {
    trace(oEvent.type);
    trace(oEvent.buttonPressed);
};

myEngine.addEventListener("pressed", oViewListener);
--------------
and this is the code in the first frame of the movieclip that works as a
building block of the menu

this.useHandCursor = true;
var oResetColor:Object = {ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:100,
ab:0};
var oPressColor:Object = {ra:100, rb:100, ga:100, gb:100, ba:100, bb:100,
aa:100, ab:100};
var oOverColor:Object = {ra:100, rb:0, ga:100, gb:50, ba:50, bb:50, aa:100,
ab:50};
var mcGboxColor:Object = new Color(mcGreenBox);
var myMovieDelegate:String = new String();
var selectedButton:Boolean = new Boolean();


function setMovieDelegate(stringSomething:String) {
    myMovieDelegate = stringSomething;
}

onRollOver = function () {
    mcGboxColor.setTransform(oOverColor);
};
onRollOut = function () {
    if (selectedButton == true) {
    } else {
        mcGboxColor.setTransform(oResetColor);
    }
};
onPress = function () {
    _root.myEngine.menuDispatcher(this);
    mcGboxColor.setTransform(oPressColor);
};
onRelease = function () {
    mcGboxColor.setTransform(oOverColor);
};
onReleaseOutside = function () {
    if (selectedButton) {
    } else {
        mcGboxColor.setTransform(oResetColor);
    }
};
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to