PDA

View Full Version : gotoandplay


mghatiya
05-14-2008, 10:27 AM
Hi,

I am trying to play a movie when a button on left menu is clicked. For that I have put a gotoAndPlay() in onRelease function for the button. But somehow the movie is not playing.
Please have a look at my code below. "trace" is printing "undefined".

I have defined a movie with name and identifier same as "sectionMovie".

Please help.

Thanks,
Mukesh




menu_item_group.menu_item._visible = false;
var xml:XML = new XML();
var total:Number;
var i:Number = 0;
var total:Number;

xml.onLoad = function()
{
var nodes = this.firstChild.childNodes;
total = nodes.length;

for (; i < total; i++)
{
menu_item_group.menu_item.duplicateMovieClip("menu_item" + i, i);
menu_item_group["menu_item" + i].over = true;
menu_item_group["menu_item" + i].item_label = nodes[i].attributes.item_label;
menu_item_group["menu_item" + i].item_no = i;
menu_item_group["menu_item" + i]._y = i * 35;
menu_item_group["menu_item" + i].flashmo_button._visible = true;
menu_item_group["menu_item" + i].over = true;
menu_item_group["menu_item" + i].flashmo_button.onRollOver = function()
{
this._parent.over = false;
};
menu_item_group["menu_item" + i].flashmo_button.onRollOut =
menu_item_group["menu_item" + i].flashmo_button.onDragOut = function ()
{
this._parent.over = true;
};
menu_item_group["menu_item" + i].flashmo_button.onRelease = function()
{
var mv = this.attachMovie(sectionMovie,"sm",getNextHeighestDepth());
mv.gotoAndPlay(2);
trace(mv.name);
};
menu_item_group["menu_item" + i].onEnterFrame = function()
{
if (this.over == true)
{
this.prevFrame();
}
else
{
this.nextFrame();
}
};
}
};
xml.load("flashmo_088_menu_item_list.xml");
xml.ignoreWhite = true;

Noct
05-14-2008, 08:00 PM
The trace is undefined for a few reasons.
First .name is not a property, ._name is.
Second, you have a misspelling in getNextHighestDepth()
Last, you need to put the linkage ID in quotes.

Try it like this:

var mv = this.attachMovie("sectionMovie", "sm", this.getNextHighestDepth());
trace(mv._name)

mghatiya
05-15-2008, 05:41 AM
Thanks Noct. Wow, I didn't expect so many mistakes in 3 lines. Though I don't understand why flash compiler doesn't detect such mistakes.

It surely helped. Although I had to remove "this." from the code you gave. I wonder why.

Now my code looks like this:
var mv = attachMovie("sectionMovie","sm",getNextHighestDepth());
mv.gotoAndPlay("start1");
//trace(mv._name);


If I don't write the line of "gotoAndPlay", the movie starts running automatically. So to avoid that I put a "stop()" action in first frame of the "sectionMovie".

After that I gave a label "start1" to second frame in the movieclip.

Now movie is coming on the stage but it is not playing.

I doubt my future in actionscript if even 2 lines of code itself can't be written correctly by me.

Please help :(

Noct
05-15-2008, 07:14 PM
Heh, well perhaps you'd want to talk to the guy who wrote the script, because he just posted it here:
http://www.actionscript.org/forums/showthread.php3?t=170477

Anyways, the "this" is giving you problems becuase at that scope, "this" is a button symbol. You cannot attach a movieClip to a button symbol. You need to figure out where it is that you want to attach the clip in question; to the main timeline, to the movieClip holding the button you clicked on, etc...

As far as the gotoandPlay not working, I would take a guess that the file isn't getting the clip attached and initialized fast enough for the script to get passed to it.

Maybe try something like this where you give it an onEnter frame to start it playing. That won't fire until the clip is attached and it will delete itself as it runs:

// Copyright © flashmo.com
// Developed by Min Thu
var totNum:Number;
menu_item_group.menu_item._visible = false;
//
var myXml:XML = new XML();
myXml.ignoreWhite = true;
myXml.load("flashmo_088_menu_item_list.xml");
myXml.onLoad = function(isLoaded:Boolean) {
if (isLoaded) {
var nodes = this.firstChild.childNodes;
total = nodes.length;
for (var i = 0; i<total; i++) {
var mI:MovieClip = menu_item_group.menu_item.duplicateMovieClip("menu_item"+i, i);
mI.over = true;
mI.item_label = nodes[i].attributes.item_label;
mI.item_no = i;
mI._y = i*35;
mI.flashmo_button._visible = true;
mI.over = true;
mI.flashmo_button.onRollOver = function() {
this._parent.over = false;
};
mI.flashmo_button.onRollOut = mI.flashmo_button.onDragOut=function () {
this._parent.over = true;
};
mI.flashmo_button.onRelease = function() {
var mV = this._parent.attachMovie("sectionMovie", "sm", this._parent.getNextHighestDepth());
mV.onEnterFrame = function() {
this.play();
delete this.onEnterFrame;
};
};
mI.onEnterFrame = function() {
if (this.over) {
this.prevFrame();
} else {
this.nextFrame();
}
};
}
}
};

mghatiya
05-16-2008, 06:48 AM
Thanks Noct. I will try this out and see if it works. And yes, I might have contacted the original author, but I thought I might as well broadcast the message instead of making only one person my victim.

And about deleting the top header of the file, I feel stupid about doing that now :)