PDA

View Full Version : how to refer to mc in .fla from imported .as



bimyou
September 8th, 2008, 01:31 PM
AS3. i give up!! please point me in the right direction...

i have a html page of .fla's that act like buttons and play external mp3s.
i will be making more buttons and fiddling with them in the future,
so i'm trying to create one Master.as that controls the basic functionality of each.

so, i've made a class as Master.as
which contains all the original code i had in the .fla.
then, i've successfully (i think) imported the package into Movie.fla.
Movie.fla has an instance "button_mc".
but i can't figure out how to refer to Movie.fla's "button_mc" from within Master.as
consequently, of course, i get a slew of "1120: Access of undefined property button_mc"

i've tried root, parent, this, that and the other thing to no avail...

Pier25
September 8th, 2008, 03:47 PM
getChildByName("button_mc").alpha = 1;

bimyou
September 9th, 2008, 01:01 AM
brilliant! i love kirupa! thanks for helping a noob. for what is likely an obvious reason to most, but a magical reason to me...

getChildByName("button_mc") as MovieClip

..seems to be working!!

so, as reference for other future noobs who might want to do something similar.
This is what i did...

1. put all the code from the original .fla into a Master.as file as a package
for example:

package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.net.URLRequest;

public class Master extends MovieClip {

public function Master() {
button_mc.buttonMode = true;
button_mc.addEventListener(MouseEvent.CLICK, go);
//etc...etc...
function go(event:MouseEvent):void{
if (button_mc.currentLabel == "over")
{
button_mc.gotoAndPlay("loading");

var s:Sound = new Sound();
var req:URLRequest = new URLRequest("http://mytune.mp3");
s.load(req);
}
}
}

2. setup a variable within the public function Master...

var button_mc:MovieClip = (getChildByName("button_mc") as MovieClip);

3. cut&paste

var req:URLRequest = new URLRequest("http://mytune.mp3");

from Master.as to the .fla.

4. make Master the document class in the properties inspector of each .fla


Now, the only code the .fla files have in the actions layer is the URLrequest.
all other behaviour is in the Master.as file. very convenient.

Hope that helps any other new guys like me!