Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Flash Actionscript / July 2008



Tip: Looking for answers? Try searching our database.

problem with as1+2

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
01900 - 03 Jul 2008 12:52 GMT
Hi,

I've got a problem with Flash CS3 and Actionscript 2.
I want to create an animation of a movieclip. This animation should start with
the click on a button. A repeated click on this button should stop the
animation. So I created a button and a movieclip and declarated them.
Additionally I defined the IDs of all this elements. But the problem is, that
nothing happens if I click the button.

But at first I should show my code:

//declaration
var myButton_btn:Button;
var myMC:MovieClip;
var isHighlighted:Boolean = false;

//code
myButton_btn.onRelease = function () {
if(isHighlighted) {
myMC.gotoAndStop (1);
isHighlighted = false;
}
else {
myMC.play();
isHighlighted=true;
} }
};

The boolean shows if the animation is already running.

The button, the movieclip and the code are located in different layers, but
they all are under the root element.

The debugger shows, that on a click event the function on myButton isn't
called.

May someone have an idea what's my fault?

Thanks and best regards,
Robert
kglad - 03 Jul 2008 14:49 GMT
you have mismatched curly brackets so you should see a compiler error.
01900 - 03 Jul 2008 15:13 GMT
sorry it was my fault
the curly brackets are a typing error in the message and when I run the file I see no compiler error but also no animation...
best regards,
Robert
kglad - 03 Jul 2008 19:32 GMT
copy and paste your code using the attach code option in this forum.
01900 - 04 Jul 2008 10:14 GMT
all right, the code is attached
________________________

//declaration
var myButton1_btn:Button;
var myButton2_btn:Button;
var myButton3_btn:Button;
var myButton4_btn:Button;

var myMC1:MovieClip;
var myMC2:MovieClip;
var myMC3:MovieClip;
var myMC4:MovieClip;

var isHighlighted:Boolean = false;
var home_btn:Button;

//code
stop();

myButton1_btn.onRelease = function () {
    if(isHighlighted) {
        myMC1.gotoAndStop (1);
        isHighlighted = false;
        }
        else {
            myMC1.play();
            isHighlighted=true;
            }
};

myButton2_btn.onRelease = function () {
    if(isHighlighted) {
        myMC2.gotoAndStop (1);
        isHighlighted = false;
        }
        else {
            myMC2.play();
            isHighlighted=true;
            }
};
           
myButton3_btn.onRelease = function() {
    if(isHighlighted){
        myMC3.gotoAndStop (1);
        isHighlighted =false;
        }
        else {
            myMC3.play();
            isHighlighted=true;
        }
};

myButton4_btn.onRelease = function () {
    if(isHighlighted) {
        myMC4.gotoAndStop (1);
        isHighlighted = false;
        }
        else {
            myMC4.play();
            isHighlighted=true;
            }
};
__smileHare - 04 Jul 2008 13:37 GMT
attachMovie("button","btn",0);
btn._x=100;
btn._y=100;
isPlay=false;

btn.onRelease = function()
{
    if(isPlay)
    {
        myMC.gotoAndStop(1);
        isPlay=false;
    }
    else
    {
        myMC.play();
        isPlay=true;
    }
}

No wrong. Your codes were right.
Maybe there is some wrong on something else.
kglad - 04 Jul 2008 16:44 GMT
that code probably isn't going to do what you want it to do.

if you want each button to play and stop its associated movieclip, you
probably want to use different boolean for each button.  so, use
this.isHighlighted instead of isHighlighted in your onRelease handlers.

but if none of your buttons are calling their onRelease handlers, you have a
more basic problem:  the instance path/names of your buttons don't match the
names in your script.
01900 - 07 Jul 2008 09:36 GMT
Hi again,

I think I figured out the problem. For testing I created a new scene. There I
created a folder and a layer in this folder. All actionscript code is located
in a root layer at the beginning of the scene.
The hierarchy looks like this:

_root
-> code_layer
-> test_layer
-> BUTTON_FOLDER
-> -> button_layer

If the button is located in the "test_layer" all works fine. But if I move the
button to the button_layer, the script isn't working.

Now my question is, how should the path to the button look like?
I tried some combinations ( _root.BUTTON_FOLDER.button_layer.myButto n and so
on) but nothing works.

Thanks again for help,
best regards,
Robert
kglad - 07 Jul 2008 18:00 GMT
layers and folders in your layers are irrelevant.  no layers are in your
published swf.

layers are used by flash to assign depths to stage objects and can be used to
determine code execution order.

so, the path to your button should be:

_root.myButton;

and it doesn't matter which layer contains your button.  only that it has the
name property that matches the name used in your actionscript.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.