Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-06-2012, 09:33 AM   #1
sattvadezign
Registered User
 
Join Date: Aug 2011
Posts: 6
Default Function variable value for menu from HTML

Hi, I have been using this as3 for my flash menu. But lately have been trying to make it SEO friendly. Hence I need to get the Value for "setSelectedBtn" from html. Im not a good at this, please help.

The scrip is as follows:

stop();
stage.frameRate = 30;
//---- add the buttons to an array --------
var buttonsArray:Array = [HomeMc,ProfileMc,PracticeMc,ProjectsMc,PressMc,Ide asMc,ContactMc,LinksMc];

var swfLoader:Loader=new Loader();
stage.addChild(swfLoader);
var url:URLRequest;

//----loop thru the buttonsArray-----
//----set some properties and add events to buttons----
function setButtons():void {
for (var i:int=0; i<buttonsArray.length; i++) {
buttonsArray[i].id = i;
buttonsArray[i].buttonMode = true;
buttonsArray[i].mouseChildren = true;
buttonsArray[i].mouseEnabled = true;
buttonsArray[i].addEventListener(MouseEvent.ROLL_OVER,Over);
buttonsArray[i].addEventListener(MouseEvent.ROLL_OUT,Out);
buttonsArray[i].addEventListener(MouseEvent.CLICK,Click);
}
}
//----fires when the mouse rolls over the button----
function Over(event:MouseEvent):void {
event.currentTarget.gotoAndPlay("over");
}
//----fires when the mouse rolls out the button----
function Out(event:MouseEvent):void {
event.currentTarget.gotoAndPlay("out");
}
//----fires when you click on the button
function Click(event:MouseEvent):void{
//----set the currentBtn variable equal with-----
//----the id of the button that was clicked-----
var currentBtn:int = event.currentTarget.id;
//----call the setSelectedBtn function
setSelectedBtn(currentBtn);
}
/*check to see witch button was clicked
if the id passed to the setSelectedBtn function
is identical with the id of the button clicked
we put that buttons in the down state (selected)
and remove all the events added to it*/
function setSelectedBtn(id:int):void{
for (var i:int=0; i< buttonsArray.length; i++) {
if (id == i) {
buttonsArray[i].gotoAndPlay("click");
buttonsArray[i].buttonMode = false;
buttonsArray[i].mouseEnabled = false;
buttonsArray[i].removeEventListener(MouseEvent.ROLL_OVER,Over);
buttonsArray[i].removeEventListener(MouseEvent.ROLL_OUT,Out);
buttonsArray[i].removeEventListener(MouseEvent.CLICK,Click);
switch(id){
case 0://---- HOME ----
url=new URLRequest("../index.html");
swfLoader.load(url);
navigateToURL(url, '_self');
break;
case 1://---- PROFILE ----
url=new URLRequest("../profile/profile.html");
swfLoader.load(url);
navigateToURL(url, '_self');
break;
case 2://---- PRACTICE ----
url=new URLRequest("../practice/practice.html");
swfLoader.load(url);
//---- navigateToURL(url, '_self');
break;
case 3://---- PROJECTS ----
url=new URLRequest("../projects/projects.html");
swfLoader.load(url);
navigateToURL(url, '_self');
break;
case 4://---- PRESS ----
url=new URLRequest("../press/press.html");
swfLoader.load(url);
navigateToURL(url, '_self');
break;
case 5://---- DESIGN IDEAS ----
url=new URLRequest("../designideas/designideas.html");
swfLoader.load(url);
navigateToURL(url, '_self');
break;
case 6://---- CONTACT US ----
url=new URLRequest("../contactus/contactus.html");
swfLoader.load(url);
navigateToURL(url, '_self');
break;
case 7://---- LINKS ----
url=new URLRequest("../links/links.html");
swfLoader.load(url);
navigateToURL(url, '_self');
break;
default:
trace("ups, something it's wrong");
break;
}
} else {
if(buttonsArray[i].currentLabel =="click"){
buttonsArray[i].gotoAndPlay("out");
}
buttonsArray[i].buttonMode = true;
buttonsArray[i].mouseEnabled = true;
buttonsArray[i].addEventListener(MouseEvent.ROLL_OVER,Over);
buttonsArray[i].addEventListener(MouseEvent.ROLL_OUT,Out);
buttonsArray[i].addEventListener(MouseEvent.CLICK,Click);
}
}
}
//----call the setButtons function----
setButtons();
setSelectedBtn(0);

///////////////////////////////////// END REFERENCE MAIN BUTTON ARRAY CODE ///////////////////////////////////////////


Thanks
SD
sattvadezign is offline   Reply With Quote
Old 08-06-2012, 03:04 PM   #2
-:)lauri
Senior Member
 
Join Date: Aug 2008
Location: Helsinki, Finland
Posts: 1,182
Default

Communication between the html page and the swf object can be done at least with javascript and flashvars or javascript and Externalinteface class.
-:)lauri is offline   Reply With Quote
Old 08-06-2012, 03:28 PM   #3
sattvadezign
Registered User
 
Join Date: Aug 2011
Posts: 6
Default

I have gone through a few examples, but im no good at scripts. I have given the AScript, if you could advise me how to make changes to it so i can call the parameter from html to give value of the "setSelectedBtn" function as "0" for example.
Thanks
SD
sattvadezign is offline   Reply With Quote
Old 08-08-2012, 07:53 AM   #4
sattvadezign
Registered User
 
Join Date: Aug 2011
Posts: 6
Default

waiting for some help to come by...
sattvadezign is offline   Reply With Quote
Old 08-08-2012, 11:45 AM   #5
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,331
Default

I don't see any swf files listed in your code: what exactly is the swfLoader used for?

Here's your code minus the unnecessary conditionals, and includes a lookup table for the data.
Also corrected the function and instance names to more closely follow standard AS3 naming conventions.
ActionScript Code:
import flash.net.*; import flash.display.*; import flash.events.*; stop(); stage.frameRate = 30; // track current and previous buttons var curr:MovieClip; var prev:MovieClip; var buttonsArray:Array = [{button:home, link:"../index.html"},  {button:profile, link:"../profile/profile.html"},  {button:practice, link:"../practice/practice.html"},  {button:projects, link:"../projects/projects.html"},  {button:presss, link:"../press/press.html"},  {button:ideas, link:"../designideas/designideas.html"},  {button:contact, link:"../contactus/contactus.html"},  {button:links, link:"../links/links.html"}]; for each (var obj in buttonsArray) {     var b:MovieClip = obj.button as MovieClip;     b.link = obj.link;     b.buttonMode = true;     b.mouseChildren = false;     b.addEventListener(MouseEvent.ROLL_OVER, over);     b.addEventListener(MouseEvent.ROLL_OUT, out);     b.addEventListener(MouseEvent.CLICK, click); } function over(event:MouseEvent):void {     curr = event.target as MovieClip;     curr.gotoAndPlay("over"); } function out(event:MouseEvent):void {     curr.gotoAndPlay("out"); } function click(event:MouseEvent):void {     disable();     trace(curr.link);     navigateToURL(new URLRequest(curr.link), "_self"); } // disable the current button function disable():void {     curr.gotoAndPlay("click");     curr.removeEventListener(MouseEvent.ROLL_OUT, out);     curr.mouseEnabled = false;     if (prev)     {         enable();     }     prev = curr; } // enable the previously disabled button function enable():void {     prev.gotoAndPlay("out");     prev.addEventListener(MouseEvent.ROLL_OUT, out);     prev.mouseEnabled = true; }

I would highly recommend that you look at the GAIA framework. (SEO)
http://www.gaiaflashframework.com/

Seminar describing GAIA in detail.
http://tv.adobe.com/watch/fitc/gaia-...r-adobe-flash/
[afz]snickelfitz is offline   Reply With Quote
Old 08-09-2012, 04:20 PM   #6
sattvadezign
Registered User
 
Join Date: Aug 2011
Posts: 6
Default

@-lauri
Thanks so much! Sorry, I cant answer any of your questions as I have no clue of what I am doing but I'm doing what I like as a final product and it's just trial and error as this website is the the first one i have ever worked on, but I'm learning.
Before i ask further questions I would like you to have a look at my website I'm working on and at the moment it is mostly flash based and has a lot of issues with SEO. I intend to change it majorly (which I have) to HTML pages with the issue that the flash menu I was using in the site online that you might see (www sattvadezign com ). The work around I had figured out was have different flash menu for each page (as I need an active button state for the current page) but I know that is least desirable. What I need is, if I can load the single flash for the user which takes a variable from the html of each page to show the active button state according to the html flash variable passed on to the flash menu loaded.( Hope, I'm making any sense, 5 beers down )
Coming back to the code you have suggested I have used it in my flash and have 2 concerns.
1. The active Button State
2. Directory structure - I have index in root and rest of pages in each folder as the code suggests, the menu flash can be in the menu folder or the root if required. ( this is to make it easier for me to develop it over time with deeper levels and yet be easily structured, as I'm no developer or a web designer, just an architect).
Please suggest
Thanks
SD
sattvadezign is offline   Reply With Quote
Old 08-11-2012, 08:45 AM   #7
sattvadezign
Registered User
 
Join Date: Aug 2011
Posts: 6
Default

Hi [afz]snickelfitz,
My reply was addressed to you sorry for pasting lauri's name. Please advise on what I have mentioned in earlier reply.
Thanks
sattvadezign is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:21 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.