PDA

View Full Version : "_root" timeline reference


sonic_2k_uk
06-26-2007, 10:46 AM
Hi,

I understand that referencing root doesnt *technically* exist in the conventional sense anymore.

I am trying to tell the root timeline to gotoAndStop through a class, but am not having much luck:

Class:

// somePackage Class

package somePackage
{

// Stage Class

public class Option
{

// Import required classes

import flash.display.DisplayObject;

// Create class variables

private var stageRef:flash.display.DisplayObject;

// Constructor Method

public function Option (stageRef:flash.display.DisplayObject)
{
this.stageRef = stageRef;
}

// createButton Method

public function createButton:Sprite
{

// Create button mc

var button:MovieClip = new MovieClip ();

// !!! ... Code to create button with click event referencing submit method and return sprite object to another class which is then displayed on the stage ... !!!

button.addEventListener (MouseEvent.CLICK, this.submit);

return button;

}

// Submit method

public function submit (event:MouseEvent):void
{
this.stageRef.gotoAndStop ('start');
}

}

}

Instantiation on timeline:

var objOption:somePackage.Option = new somePackage.Option (this);

I get the following error:

1061: Call to a possibly undefined method gotoAndStop through a reference with static type flash.display:DisplayObject.

Any help is very much appreciated!

angels.of.promise
06-26-2007, 10:52 AM
I'm a total noob to AS but i think you need to import the class that has gotoandstop in it before you can use it. does import flash.display.DisplayObject; do this? i'm not sure. sorry if this is just confusing i'm still learning.


Hi,

I understand that referencing root doesnt *technically* exist in the conventional sense anymore.

I am trying to tell the root timeline to gotoAndStop through a class, but am not having much luck:

Class:

// somePackage Class

package somePackage
{

// Stage Class

public class Option
{

// Import required classes

import flash.display.DisplayObject;

// Create class variables

private var stageRef:flash.display.DisplayObject;

// Constructor Method

public function Option (stageRef:flash.display.DisplayObject)
{
this.stageRef = stageRef;
}

// createButton Method

public function createButton:Sprite
{

// Create button mc

var button:MovieClip = new MovieClip ();

// !!! ... Code to create button with click event referencing submit method and return sprite object to another class which is then displayed on the stage ... !!!

button.addEventListener (MouseEvent.CLICK, this.submit);

return button;

}

// Submit method

public function submit (event:MouseEvent):void
{
this.stageRef.gotoAndStop ('start');
}

}

}

Instantiation on timeline:

var objOption:somePackage.Option = new somePackage.Option (this);

I get the following error:

1061: Call to a possibly undefined method gotoAndStop through a reference with static type flash.display:DisplayObject.

Any help is very much appreciated!

sonic_2k_uk
06-26-2007, 11:05 AM
Same boat at me =D

My understanding is that the flash.display.DisplayObject allows you to reference and create instances of that type, and this provides you with any properties and methods of that type. Just as if you imported any other class.

flash.display.stage does not seem to have the gotoAndStop method, so i need to find a way to reference the root timeline so that i can access the gotoAndStop method for it. I presumed the stage type allows me to do this!

panel
06-26-2007, 11:49 AM
First of all you don't have to use full package path to define variable (just use import statement and then you can use only object name).

Secound Display object dosen't have gotoAndStop methos. only Movie Clip has, so your main document class should extend MovieClip if you want to control timeline.

Chech out those tutorials (http://www.helpqlodhelp.com/blog/archives/000127.html). They helped me a lot when I was starting to learn as3.

Also languae reference (http://livedocs.adobe.com/flex/201/langref/index.html) become very usefull over time.

sonic_2k_uk
06-26-2007, 12:16 PM
Many thanks panel, have actually just solved the problem a different way :)

AS3 is as ive read, very different to previous versions!

Problem solved by modifying the submit method to the following:


// Submit method

public function submit (event:MouseEvent):void
{
event.target.root.gotoAndStop ('start');
}

This uses the targetted movie clip on the stage to reference the stage root.