PDA

View Full Version : actionscript 3 help - linking


bythescruff
09-17-2008, 02:36 PM
Dear all,

I recently created a site for a client which is half css, xhtml and right hand side is flash based with video.

the flash contains 3 _mc s and within the movieclip is a btn.

What i want to do is know how do i link the button within the movieclip to play a section of the root. e.g frame 25.

I have tried for hours now and have no idea, its becoming a nightmare.

If anyone can help me please do.

thanks
bythescruff

wvxvw
09-17-2008, 04:18 PM
myButton.addEventListener(MouseEvent.CLICK, handleClick);
function handleClick(evt:Event):void
{
myMovieClip.gotoAndPlay(25);
}
Assuming:
myButton is on the timeline where you put this script and "myButton" is the name you entered into Instance Name field on the properties bar.
myMovieClip is the reference to the clip you want to play, it should be accessible from the same scope where you put this script. To reference the clip containing the script use "this" keyword.
If the button and clip are not a child and parent, than, you'll need to either get the reference to the child by calling
var button:SimpleButton = (buttonGrandParent.getChildByName(
"buttonParent") as DisplayObjectContainer).getChildByName("button") as SimpleButton;
or, vice versa:
var buttonParent:Sprite = (parent() as DisplayObjectContainer).parent() as Sprite;
But it shouln't be as sophisticated as it seems, most probably you'll have less code than it is here :)

bythescruff
09-18-2008, 02:41 PM
Hi,

it has worked for one the movie, but if u have say 3 movies on on the scene, and apply that code like this in the top of scene:

home_mc.addEventListener(MouseEvent.CLICK, handleClick);
function handleClick(evt:Event):void
{
gotoAndPlay(1);
}
sandwich_mc.addEventListener(MouseEvent.CLICK, handleClick);
function handleClick(evt:Event):void
{
gotoAndPlay(51);
}
lunch_mc.addEventListener(MouseEvent.CLICK, handleClick);
function handleClick(evt:Event):void
{
gotoAndPlay(101);
}

It seems to make the swf file mess up and not find the videos.


How can i fix this?

--------------

Also on the movies i had a rollover on the button which doesn't seem to appear now as when i had in as2.

wvxvw
09-18-2008, 02:58 PM
You're adding the same listener to all the buttons, moreover, you're trying to redefine that listener many times, this should result in error saying something like "you cannot have multiple definitions for the same function".
You should either add different listeners, or, better, add only one listener and make it behave differently depending on what the event target is:
function handleClick(evt:Event):void
{
switch(evt.target)
{
case home_mc:
gotoAndPlay(1);
break;
case sandwich_mc:
gotoAndPlay(51);
break;
case lunch_mc:
gotoAndPlay(101);
break;
}
}

bythescruff
09-18-2008, 03:35 PM
hi,

I put the code in and the only error i get is this: when u click on a movie it dont seem to go to the path it should like if home_mc was going to 51 it wont work.

Actions on button or MovieClip instances are not supported in ActionScript 3.0. All scripts on object instances will be ignored.
TypeError: Error #1010: A term is undefined and has no properties.
at SkinUnderAll_fla::MainTimeline/frame1()


Any ideas

thanks

wvxvw
09-18-2008, 03:39 PM
The error is exactly what it says: you don't write your code on buttons or clips. You write it in external classfiles / on the timeline.

bythescruff
09-18-2008, 03:45 PM
the problem is just a skin for the video not the code, as all code is on the root in its one cell, all objects are without code.

Still the videos when clicked on do not go to the movies through should on the time line.

Any idea?

wvxvw
09-18-2008, 03:49 PM
home_mc or sandwich_mc or lunch_mc are not children of the clip containing the code.

bythescruff
09-18-2008, 04:05 PM
Hi,

i have attached a image to show what i mean and the code i have placed in. If you can see why it dont work please let me know.

http://www.bythescruff.com/ICBINB/for-flash-forum.gif

thanks
bythescruff

wvxvw
09-18-2008, 04:23 PM
Why do you need to navigate between frames? You can just switch .source property of FLVPlayBack component to load different FLV...

Technically, the error: "Error #1010: A term is undefined and has no properties" means that some variable, say, "home_mc" doesn't point to anything. This may happen for many different reasons:
- misspeled name.
- the clip it has to point to doesn't exist when the first reference to this variable occures.
- the clip it should be pointing to isn't visible from the variable declaration scope. I.e. the clip "home_mc" isn't a child of the clip where you have home_mc.addEventListener().

bythescruff
09-18-2008, 04:36 PM
so are you saying i should link the buttons movie files to a source of where the video is?

could you please give an example of the code.

wvxvw
09-18-2008, 05:17 PM
Here's an example.

bythescruff
09-19-2008, 09:31 AM
thank you