View Full Version : button problems

11-23-2011, 08:31 PM
Hello. I'm fairly new to the world of actionscript so let me try to explain what I'm trying to do in details. In scene one I have 2 movie clips (homepage (2) musicpage (3)). Inside the homepage movieclip is another movie clip(bckground2) with my animations. at the end of the last frame in the timeline my button pops up (musicbutton). So the idea is when a user clicks the button they navigate back to musicpage (frame3) in the main scene. I tried using this code "_root.gotoAndPlay(3) but is doesn't work properly. can someone help me come up with a code?

11-24-2011, 02:50 AM

Looks like ActionScript 2 or 1. In what they referred to as ActionScript 1, code was placed on the button (object on Stage). ActionScript 2 used anonymous functions in timeline. The symbol instances need to be named so you can "talk" to them with ActionScript, and you need to specify the event --

e.g., for AS 1
on(press) { gotoAndPlay(3); }
or for AS 2
this.blue_mc.onPress = function ()
{ gotoAndStop(2); }

The keyword this would reference the current timeline so you could use dot syntax to address nested movie clips -- this.blue_mc.nested_mc.onPress =

Referencing the main timeline (_root or root) from within nested movie clips can be tricky. A simple solution would be to have buttons on Stage. What version Flash are you using?

It's hard to visualize what you are doing. Open Window>Movie Explorer and copy the code to clipboard and then paste that into a post so we might see what you have.

11-24-2011, 06:24 AM
thank you auntnini from replying. I'm using cs 5.5. The code worked Thanks so much!!

11-24-2011, 06:35 AM
I just bumped into a new problem. the code worked just fine but now I added a preloader scene. now when you press the button instead of navigating to the laboratory page it goes to the preloader scene. what additional code would I need to navigate to scene 2?

11-29-2011, 12:52 AM
It is safer to create a LABEL for frames because numbers may change if you add/delete frames. Click frame in timeline and enter LABEL info in Properties panel. You should have some IF/ELSE logic when bytesLoaded -- bytesTotal to go back to and repeat preloader frame or proceed on to animation frame.

With FLASH CS 5.5 you can choose between creating an ActionScript 2.0 or ActionScript 3.0 document. The two versions are not compatible. AS3.0 is more complicated but worth learning if you are serious about working with Flash.

Here is AS3.0 sample preloader code

Scene 1
Actions for Frame 1
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoading);
this.loaderInfo.addEventListener(Event.COMPLETE, onComplete);
function onLoading(evt:ProgressEvent):void {
var loaded:Number = evt.bytesLoaded / evt.bytesTotal;
percent_txt.text = (loaded*100).toFixed(0) + "%";
function onComplete(event:Event):void {
this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS, onLoading);
this.loaderInfo.removeEventListener(Event.COMPLETE, onComplete);

11-29-2011, 01:29 AM
Here's some OLD ActionScript 2.0 code referencing (_level0.dummy_mc._framesloaded == _level0.dummy_mc._totalframes)

Scene 1
Actions for Frame 1
//_level0.dummy_mc.content._lockroot = true; _root.onEnterFrame = function() {
//loadMovieNum("preloader.swf", 2);
loadText = Math.round((dummy_mc.getBytes.Loaded() / dummy_mc.getBytesTotal())*100) + " % Loaded";

/*var percent = Math.round(_level0.dummy_mc.getBytesLoaded() / _level0.dummy_mc.getBytesTotal())*100;
_level0.loadText = (percent) = " % loaded";
}; */

start_btn.onPress = function() {
loadMovieNum("preloader.swf", 2);
loadMovie("slideLoad.swf", dummy_mc);
_level0.onEnterFrame = function() {
if (_level0.dummy_mc._framesloaded == _level0.dummy_mc._totalframes) {
_level0.load_txt._visible = false;
stop_btn.onPress = function() {
Actions for Frame 5

Loader, ‹dummy_mc›
circleBUTTON, ‹start_btn›
circleBUTTON, ‹stop_btn›
(empty), (loadText), ‹load_txt›