Discussion:
Convert my website to AS3
(too old to reply)
Anna Gatta
2009-03-11 11:13:13 UTC
Permalink
I want to use labels with the gotoAndStop, but in CS4 I don't get it to work
:-/
I also would like some tips on how to make the "active" menu non-active while
you are on its page. Here is some code I have been trying, but it seems like I
need to do an addEventListener and I just can't figure it out... Any help would
be highly appreciated!
------------------------------
stop();
home_btn.onRelease = function () {
gotoAndStop("home");
}

stop();
projects_btn.onRelease = function () {
gotoAndStop("projects");
}

stop();
portfolio_btn.onRelease = function () {
gotoAndStop("portfolio");
}

stop();
clients_btn.onRelease = function () {
gotoAndStop("clients");
}

clients_btn.enabled = false;

----------------------------------
NedWebs
2009-03-11 12:06:16 UTC
Permalink
In AS3 you need to use event listeners and event handler functions for any
interactive objects, and many other things as well. The following shows how it
would be done for the home button:

// the event handler function
function homeClicked(evt:MouseEvent):void {
gotoAndStop("home");
}

// the event listener
home_btn.addEventListener(MouseEvent.CLICK, homeClicked);

You only need one stop(); per any frame

And to disable the button, you could either just not assign the event listener
or use:

home_btn.mouseEnabled = false;

It's not clear how you have this designed, but it would be best to have the
buttons only being assigned an event listener once for the whole file, and not
on every page
Anna Gatta
2009-03-11 14:05:58 UTC
Permalink
Hi Ned and thanks for your reply. I have now the following layers (from top to
bottom):
labels (here I use the label names "home" etc. and have a stop(); action)
actions (general actions for external movies etc)
actions menu (here I would use the code you gave me, but just once in the
first frame?)
menu buttons (here I have the buttons repeated for each "label" since I want
them to be in another color when non-active
content (well - the content)

Is that correct?

I tried a test and I get: "The class or interface "MouseEvent"could not be
loaded."
I copy/pasted your code, but maybe you didn't wrote all I needed, not knowing
I am far from a code geek? :-)
Anna Gatta
2009-03-11 14:23:30 UTC
Permalink
Oh, I had the document as AS2... Now it works. One question: if I want the
buttons to be inactive when on its page, how do I do that in AS3 so that I
don't need to add a new code for each label?

Because - if I do as you wrote below I would need to have specific code for
each label right?
[i]And to disable the button, you could either just not assign the event
listener or use:
home_btn.mouseEnabled = false;[/i]
NedWebs
2009-03-11 14:29:36 UTC
Permalink
Chances are you still have your Publish Settings set up for AS1/2 rather than
AS3, that should resolve the MouseEvent error.

As for the rest, If you duplicate the buttons in different pages, then you
need to reassign their code for those pages.

My scenario would have all pages in the same scene/timeline and the buttons
living on their own layer extending the full length of it, along with an
actions layer containing their code that also extends that length. This
probably doesn't agree with what you want though.
Anna Gatta
2009-03-11 15:32:43 UTC
Permalink
I now should have all code correct, .FLA is in AS3, but the web site is now
playing each page, not stopping at HOME after loading... I have a stop action
in the beginning of each label on a separate layer.

On HOME I have an external movie with the code:
loadMovie("home_movie_2.swf", "home_movie_mc");
stop();

But it doesn't stop. I learned the basics of AS2 very fast and now I am lost
in basic stuff ... :-/

My code for the buttons are now in frame 3 just after the loading:
stop();
home_btn.addEventListener(MouseEvent.CLICK, homeClicked);
function homeClicked(event:MouseEvent):void {
gotoAndStop("home");
}
projects_btn.addEventListener(MouseEvent.CLICK, projectsClicked);
function projectsClicked(event:MouseEvent):void {
gotoAndStop("projects");
}
portfolio_btn.addEventListener(MouseEvent.CLICK, portfolioClicked);
function portfolioClicked(event:MouseEvent):void {
gotoAndStop("portfolio");
}
clients_btn.addEventListener(MouseEvent.CLICK, clientsClicked);
function clientsClicked(event:MouseEvent):void {
gotoAndStop("clients");
}
testimonials_btn.addEventListener(MouseEvent.CLICK, testimonialsClicked);
function testimonialsClicked(event:MouseEvent):void {
gotoAndStop("testimonials");
}
news_btn.addEventListener(MouseEvent.CLICK, newsClicked);
function newsClicked(event:MouseEvent):void {
gotoAndStop("news");
}
contact_btn.addEventListener(MouseEvent.CLICK, contactClicked);
function contactClicked(event:MouseEvent):void {
gotoAndStop("contact");
}

What do I do wrong?? Ned - if you have the time to answer once again I would
be so thankful.
NedWebs
2009-03-11 16:12:34 UTC
Permalink
loadMovie is not AS3, so it's likely losing its mind. Research AS3's Loader class for importing other visual files
Loading...