A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Pass variable from MC to _root

Hybrid View

  1. #1
    Member
    Join Date
    Jul 2007
    Posts
    65

    Pass variable from MC to _root

    Hi,

    I have a movieclip that is loaded from the main timeline. Within that mc I have a button that when clicked I want to pass a variable back to a function within the main timeline.

    The below bold string is what I want to pass as a variable from the button click event in the mc to the function LoadGallery in the main timeline.

    Code:
    Defines the xml path to pass to the function
    
    function loadGallery1(){
        loadGallery("Flash/gallery1.xml");   
    }
    
    
    Calls LoadGallery function and recieves the xml path:
    
    function loadGallery(galName){
        _root.xmlDataPath = galName;  
        mcLoader.loadMovie("Flash/viewer.swf");
    }
    
    
    Calls function to run it:
    
    loadGallery1();
    All of the above code resides in the main timeline (_root), I don't show a button click event here from the mc because I don't have one. All I need that button click event to do is to populate that bold string above.

    Can anyone help me with this?

    thanks
    Last edited by frosty1_4me; 08-09-2007 at 09:57 PM.

  2. #2
    Member
    Join Date
    Jul 2007
    Posts
    65
    Ok, correct me if this is the wrong way of doing things. I solved the problem and heres what I did.

    I changed the function that's in the main timeline (_root) to this:

    Code:
    //Set button actions
    function loadGallerys(){
    
    //myRootXMLGalleryPath is defined in the buttonClick event
        loadGallery(myRootXMLGalleryPath);
       
    }
    Then in my mc where the button click occurs, I put this in the onRelease function of the button:

    Code:
    //used in the _root timeline.
    
    var mygallery:String = "Flash/gallery1.xml";		
    _root.myRootXMLGalleryPath = mygallery
    		
    _root.play();
    	}
    }
    This seems to work for all my buttons now, I just have to define the strings within those button events. Is that the proper way of doing things?

    thanks

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