Skip to main content
Inspiring
November 19, 2010
Answered

Configure AS3 dropdown into existing project

  • November 19, 2010
  • 2 replies
  • 804 views

I have a project which was completed, now I need to add a dropdown menu but how do I impliment the code into the existing actionscript I have?


ACTIONSCRIPT / CURRENT

var Xpos:Number = 0;
var Ypos:Number = 0;
var swf:MovieClip;
var loader:Loader = new Loader();

var defaultSWF:URLRequest = new URLRequest("swfs/home.swf");

loader.load(defaultSWF);
loader.x = Xpos;
loader.y = Ypos;
addChild(loader);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Btns Universal function
function btnClick(event:MouseEvent):void {


    SoundMixer.stopAll();
    removeChild(loader);
    var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf");
    loader.load(newSWFRequest);
    loader.x = Xpos;
    loader.y = Ypos;
    addChild(loader);
}

   
// Btn listeners
home.addEventListener(MouseEvent.CLICK, btnClick);
commercial.addEventListener(MouseEvent.CLICK, btnClick);
films.addEventListener(MouseEvent.CLICK, btnClick);
videomontage.addEventListener(MouseEvent.CLICK, btnClick);
contact.addEventListener(MouseEvent.CLICK, btnClick);

ACTIONSCRIPT FOR DROPDOWN

menu.heading.myText.text = "Websites";

menu.panel.b1.myText.text = "Amazon";
menu.panel.b2.myText.text = "Google";

menu.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(event:MouseEvent):void {
    if(event.target == menu.panel.b1) {
        navigateToURL(new URLRequest("http://www.amazon.com"));
    }
    if(event.target == menu.panel.b2) {
        navigateToURL(new URLRequest("http://www.google.com"));
   
}
}    

????

This topic has been closed for replies.
Correct answer Ned Murphy

You can probably leave the code where it is and just plant the movieclip where you want it.  If you move the code to another timeline then you need to adjust the targeting.  Since the commands are only to open new web pages, you don't need to relocate/edit the code .

2 replies

mentlityAuthor
Inspiring
November 19, 2010

OK, I got the first part to work, used a different dropdown but now my problem is the original AS calls the green

see red  blue and green below

var Xpos:Number = 0;
var Ypos:Number = 0;
var swf:MovieClip;
var loader:Loader = new Loader();

var defaultSWF:URLRequest = new URLRequest("swfs/home.swf");

loader.load(defaultSWF);
loader.x = Xpos;
loader.y = Ypos;
addChild(loader);
//////////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////
// Btns Universal function
function btnClick(event:MouseEvent):void {


    SoundMixer.stopAll();
    removeChild(loader);
    var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf");
    loader.load(newSWFRequest);
    loader.x = Xpos;
    loader.y = Ypos;
    addChild(loader);
}

   
// Btn listeners
home.addEventListener(MouseEvent.CLICK, btnClick);
commercial.addEventListener(MouseEvent.CLICK, btnClick);
menu.addEventListener(MouseEvent.CLICK, btnClick);
videomontage.addEventListener(MouseEvent.CLICK, btnClick);
contact.addEventListener(MouseEvent.CLICK, btnClick);

DROPDOWN ACTIONSCRIPT IN MOVIECLIP

menu.addEventListener(MouseEvent.CLICK, btnClick);

function btnClick(event:MouseEvent):void {
var main1URL:URLRequest = new URLRequest("http://www.adobe.com");
navigateToURL(main1URL, "_self");
}

/////////////////////////////////////////     END REFERENCE CLICK CODE    ///////////////////////////////////////////

// Event Listeners for all 3 main buttons
menu.addEventListener(MouseEvent.ROLL_OVER, main1Over); button now has two functions
/*
mainBtn2.addEventListener(MouseEvent.ROLL_OVER, main2Over); I have two d downs so i would name these menu1 / menu2?
mainBtn3.addEventListener(MouseEvent.ROLL_OVER, main3Over);


// ROLL_OVER fuctions for all 3 main buttons
function main1Over(event:MouseEvent):void {
gotoAndPlay("down1");
}I would need to add the original function for these or re name? to call the swfs (above in green),

function main2Over(event:MouseEvent):void {
gotoAndPlay("down2");
}
/*
function main3Over(event:MouseEvent):void {
gotoAndPlay("down3");
}
*/

Ned Murphy
Legend
November 19, 2010

You can probably just add it as you show it, all in the same frame.  Then give your menu the instance name "menu".

mentlityAuthor
Inspiring
November 19, 2010

Ok, understood but the dropdown menu is inside a movieclip, do I cut and paste the code to the main timeline where the rest of the as sits?

RRR

???

Ned Murphy
Ned MurphyCorrect answer
Legend
November 19, 2010

You can probably leave the code where it is and just plant the movieclip where you want it.  If you move the code to another timeline then you need to adjust the targeting.  Since the commands are only to open new web pages, you don't need to relocate/edit the code .