Skip to main content
April 4, 2011
Question

STORING CODE INSIDE A VARIABLE?

  • April 4, 2011
  • 1 reply
  • 1006 views

Code.

function abc()

{

Object(parent).play();

}

The code above works but i want to store Object(parent) inside a variable for easy use. I don't know a dataType for storing codes inside a variable.

Code containing variable.

function abc()

{

c.play();

}

var c:??? = Object(parent);

This topic has been closed for replies.

1 reply

robdillon
Participating Frequently
April 4, 2011

Either var c:* = Object(parent); or var c:Object = Object(parent); will work.

April 4, 2011

var c:Object = Object(parent);

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at Untitled_fla::container_1/abc()

at Untitled_fla::MainTimeline/frame1()

var c:* = Object(parent);

TypeError: Error #1010: A term is undefined and has no properties.

at Untitled_fla::container_1/abc()

at Untitled_fla::MainTimeline/frame1()

* & Object = Wrong data types.

Chipleh
Inspiring
April 4, 2011

Your code works fine for me, using the following as a test:

1. In a new file, add 10 frames, with a stop(); at the first frame
2. Create Movie Clip, give it a motion tween over the 10 frames
3. Inside the movie clip, add this code:

function abc(Event:MouseEvent)
{
c.play();
}
var c:Object = Object(parent);
c.addEventListener(MouseEvent.MOUSE_DOWN, abc);

4. Click the movie clip, watch it play.

~chipleh