So i'm having a tiny bit of trouble adjusting to as3. i cant seem to call functions written on the root timeline from any nested movie clips.
for example:
on frame1 of the root timeline i write a simple function:
function greet(){
trace("hello");
}
i then create a movie clip and put it on the stage. on its first frame i call the previous function like so:
root.greet()
but instead of getting traced "hello" i get this compile error:
1061: Call to a possibly undefined method changeActiveFrame through a reference with static type flash.display:DisplayObject.
now, i somewhat understand whats going on, but i have no idea how to fix it. searching for this specific error yields a bunch of unrelated flex problems.
any help would be wonderful, thanks!
as3 calling root functions from a nested movieclip
Started by
greggreg
, Jun 15 2007 04:45 PM
2 replies to this topic
#1
Posted 15 June 2007 - 04:45 PM
#2
Posted 21 June 2008 - 08:32 PM
hello. i was struggling with the same thing and found an example that works. the code is posted below along with the link to the original post. i also attached the zip file of the working example.
Main swf--------
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
var loader:Loader = new Loader();
// find out when Loader has COMPLETEd and INITed (1st frame initialized)
loader.contentLoaderInfo.addEventListener(Event.INIT, loaderInitHandler);
loader.load(new URLRequest("Slides.swf"));
addChild(loader);
function loaderInitHandler(event:Event):void
{
// Access the "_root" timeline of the loaded swf with..
trace(loader.content);
// remember we've told the Events to bubble
loader.content.addEventListener("gotoNextSlide", gotoNextSlideHandler);
loader.content.addEventListener("gotoPrevSlide", gotoPrevSlideHandler);
}
function gotoNextSlideHandler(event:Event):void
{
var mainTimeline:MovieClip = MovieClip(loader.content);
mainTimeline.gotoAndStop(mainTimeline.currentFrame+1);
}
function gotoPrevSlideHandler(event:Event):void
{
var mainTimeline:MovieClip = MovieClip(loader.content);
mainTimeline.gotoAndStop(mainTimeline.currentFrame-1);
}
Nested swf --------
1st frame in file
import flash.events.MouseEvent;
stop();
nextBtn.addEventListener(MouseEvent.CLICK, nextBtnClickHandler);
function nextBtnClickHandler(event:MouseEvent):void
{
// notice I've set "bubble" to false, because we will be listening
// directly to the main timeline in which this function is defined and ran
dispatchEvent(new Event("gotoNextSlide", false));
}
3rd frame in file
import flash.events.MouseEvent;
prevBtn.addEventListener(MouseEvent.CLICK, prevBtnClickHandler);
function prevBtnClickHandler(event:MouseEvent):void
{
dispatchEvent(new Event("gotoNextSlide", false));
}
original post -------- http://flashmove.com...123824#poststop
hope this helps )
hello. i was struggling with the same thing and found an example that works. the code is posted below along with the link to the original post. i also attached the zip file of the working example.
Main swf--------
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
var loader:Loader = new Loader();
// find out when Loader has COMPLETEd and INITed (1st frame initialized)
loader.contentLoaderInfo.addEventListener(Event.INIT, loaderInitHandler);
loader.load(new URLRequest("Slides.swf"));
addChild(loader);
function loaderInitHandler(event:Event):void
{
// Access the "_root" timeline of the loaded swf with..
trace(loader.content);
// remember we've told the Events to bubble
loader.content.addEventListener("gotoNextSlide", gotoNextSlideHandler);
loader.content.addEventListener("gotoPrevSlide", gotoPrevSlideHandler);
}
function gotoNextSlideHandler(event:Event):void
{
var mainTimeline:MovieClip = MovieClip(loader.content);
mainTimeline.gotoAndStop(mainTimeline.currentFrame+1);
}
function gotoPrevSlideHandler(event:Event):void
{
var mainTimeline:MovieClip = MovieClip(loader.content);
mainTimeline.gotoAndStop(mainTimeline.currentFrame-1);
}
Nested swf --------
1st frame in file
import flash.events.MouseEvent;
stop();
nextBtn.addEventListener(MouseEvent.CLICK, nextBtnClickHandler);
function nextBtnClickHandler(event:MouseEvent):void
{
// notice I've set "bubble" to false, because we will be listening
// directly to the main timeline in which this function is defined and ran
dispatchEvent(new Event("gotoNextSlide", false));
}
3rd frame in file
import flash.events.MouseEvent;
prevBtn.addEventListener(MouseEvent.CLICK, prevBtnClickHandler);
function prevBtnClickHandler(event:MouseEvent):void
{
dispatchEvent(new Event("gotoNextSlide", false));
}
original post -------- http://flashmove.com...123824#poststop
hope this helps )
Main swf--------
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
var loader:Loader = new Loader();
// find out when Loader has COMPLETEd and INITed (1st frame initialized)
loader.contentLoaderInfo.addEventListener(Event.INIT, loaderInitHandler);
loader.load(new URLRequest("Slides.swf"));
addChild(loader);
function loaderInitHandler(event:Event):void
{
// Access the "_root" timeline of the loaded swf with..
trace(loader.content);
// remember we've told the Events to bubble
loader.content.addEventListener("gotoNextSlide", gotoNextSlideHandler);
loader.content.addEventListener("gotoPrevSlide", gotoPrevSlideHandler);
}
function gotoNextSlideHandler(event:Event):void
{
var mainTimeline:MovieClip = MovieClip(loader.content);
mainTimeline.gotoAndStop(mainTimeline.currentFrame+1);
}
function gotoPrevSlideHandler(event:Event):void
{
var mainTimeline:MovieClip = MovieClip(loader.content);
mainTimeline.gotoAndStop(mainTimeline.currentFrame-1);
}
Nested swf --------
1st frame in file
import flash.events.MouseEvent;
stop();
nextBtn.addEventListener(MouseEvent.CLICK, nextBtnClickHandler);
function nextBtnClickHandler(event:MouseEvent):void
{
// notice I've set "bubble" to false, because we will be listening
// directly to the main timeline in which this function is defined and ran
dispatchEvent(new Event("gotoNextSlide", false));
}
3rd frame in file
import flash.events.MouseEvent;
prevBtn.addEventListener(MouseEvent.CLICK, prevBtnClickHandler);
function prevBtnClickHandler(event:MouseEvent):void
{
dispatchEvent(new Event("gotoNextSlide", false));
}
original post -------- http://flashmove.com...123824#poststop
hope this helps )
hello. i was struggling with the same thing and found an example that works. the code is posted below along with the link to the original post. i also attached the zip file of the working example.
Main swf--------
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
var loader:Loader = new Loader();
// find out when Loader has COMPLETEd and INITed (1st frame initialized)
loader.contentLoaderInfo.addEventListener(Event.INIT, loaderInitHandler);
loader.load(new URLRequest("Slides.swf"));
addChild(loader);
function loaderInitHandler(event:Event):void
{
// Access the "_root" timeline of the loaded swf with..
trace(loader.content);
// remember we've told the Events to bubble
loader.content.addEventListener("gotoNextSlide", gotoNextSlideHandler);
loader.content.addEventListener("gotoPrevSlide", gotoPrevSlideHandler);
}
function gotoNextSlideHandler(event:Event):void
{
var mainTimeline:MovieClip = MovieClip(loader.content);
mainTimeline.gotoAndStop(mainTimeline.currentFrame+1);
}
function gotoPrevSlideHandler(event:Event):void
{
var mainTimeline:MovieClip = MovieClip(loader.content);
mainTimeline.gotoAndStop(mainTimeline.currentFrame-1);
}
Nested swf --------
1st frame in file
import flash.events.MouseEvent;
stop();
nextBtn.addEventListener(MouseEvent.CLICK, nextBtnClickHandler);
function nextBtnClickHandler(event:MouseEvent):void
{
// notice I've set "bubble" to false, because we will be listening
// directly to the main timeline in which this function is defined and ran
dispatchEvent(new Event("gotoNextSlide", false));
}
3rd frame in file
import flash.events.MouseEvent;
prevBtn.addEventListener(MouseEvent.CLICK, prevBtnClickHandler);
function prevBtnClickHandler(event:MouseEvent):void
{
dispatchEvent(new Event("gotoNextSlide", false));
}
original post -------- http://flashmove.com...123824#poststop
hope this helps )
Attached Files
#3
Posted 10 July 2008 - 05:38 PM
there is no "root", a MovieClip has a stage property, just call movieclip.stage.myfunction
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users