0

I have set the instance name of MovieClip to char and when i try to compile this code i get 2 Errors:

package com.game
{

import flash.display.MovieClip;
import flash.events.*;


public class game extends MovieClip
{
    var gravity = 0.8;
    var velocity = 0;
    char.addEventListener(Event.ENTER_FRAME,isHitted);

    function isHitted(event:Event):void
    {
        if (char.hitTestObject(level1))
        {
            velocity++;
            char.y -= gravity+velocity;
        }
        else
        {

        }
    }

Errors:

.../game.as, Line 13    1120: Access of undefined property char.
../game.as, Line 13 1120: Access of undefined property isHitted.

2 Answers 2

2

First off, it sounds like this class definition is the definition for the instance you are referring to, if it is, you should use 'this' instead of 'char'

Also, you typically do not specify method calls like:

char.addEventListener(Event.ENTER_FRAME,isHitted);

outside of methods when declaring a class. Instead, that line of code should exist inside of a constructor or a method that is called during the instantiation of the MovieClip.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to make 'char' accessible to 'game' before being able to use it.

One way is to pass 'char' as parameter when you instantiate 'game'.

Two ways of doing this are described in the answer of @lee-burrows in Access caller object when using composition in AS3

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.