Importing SWF as hitTestState
Preface: I'm making a map of the 50 US States using imported images.
I'm using a piece of XML to import image paths into Loaders, and then using the Loaders to populate multiple movie clips (this works fine). I find myself now needing to import SWFs in the shape of each US State as a hitTestState for the 50 buttons. It's been suggested I use a seperate Class to define the new button states, but I'm afraid my programming skills haven't evolved far enough for me to understand how I can:
a. pass the XMLList information containing the SWF paths to a new class b. populate the hitTestState (s) of the 50 buttons with a for loop
Here is the function I've been using to populate the images into the individual buttons. I figured I would use this same function to generate or populate a button into which I could send the SWFs as hitTestState.
private function populateButtonImages(): void {
//var hoverState:StateBut = new StateBut();//
for(var i:int = 0; i <= total; i++){
offLoader = new Loader();
hoverLoader = new Loader();
//hitLoader = new Loader();
var offName:String = pathage + _activeImage[i].toString();
var hoverName:String = pathage + _hoverImage[i].toString();
//var hitName:String = pathage + _hitState[i].toString();
offLoader.load(new URLRequest(offName));
hoverLoader.load(new URLRequest(hoverName));
//hitLoader.load(new URLRequest(hitName));
this["button" + i].offImage.addChild(offLoader);
this["button" + i].hoverImage.addChild(hoverLoader);
//this["button" + i].hitButton.addChild(hitLoader);
//this["button" + i].hitButton = new StateBut();//
this["button" + i].hoverImage.mouseEnabled = false;
开发者_Go百科 //this["button" + i].buttonMode = true;
//moves hover image to more appropriate location over button
this["button" + i].hoverImage.x = _hoverOffsetX[i];
this["button" + i].hoverImage.y = _hoverOffsetY[i];
}
addMapButtonListeners();
}
I've commented out the lines for my original attempt at adding the SWFs to the clips as hitStates.
In a perfect world, I would like to just make 50 buttons, populate the up, over and hitStates of the buttons and not have to worry about performing hitTests on MovieClips and a variety of other problems I've already solved so far.
Help? Advice is welcome. Knowledge is power.
If you have the hitareas as vectors and the graphics for each state, then it might be easier to just create the buttons manually in the Flash IDE? You could then "Export for Actionscript" each button and export as one SWF.
In your main project you could load the SWF and have access to all the working buttons.
精彩评论