0

im trying to make a function that will be used in multiple projects and save , load or display a high score table depending on the parameters entered. my current code is

function test(action:String):void {
    if (action == "loadHS") {
        trace("loading")
    } else if (action == "save") {
        trace("saveinghs")
    } else if (action == null) {
        trace("please provide an operation for high score table")
    } else {
        trace(" the action" + action + "is not a valid action");
    }
}

test(loadHS);

witch creates the following compiler error.

Scene 1, Layer 'Layer 1', Frame 1, Line 14  1120: Access of undefined property loadHS.

what am i doing wrong? thanks :)

2 Answers 2

1

The variable loadHS is not yet defined. This means it is declared, but you need to give it a value to define it.

var loadHS:String = "loadHS";

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

1 Comment

changed code to var action:String function test(action:String):void { if (action == "loadHS") { trace("loading") } else if (action == "save") { trace("saveinghs") } else if (action == null) { trace("please provide an operation for high score table") } else { trace(" the action" + action + "is not a valid action"); } } test(action = "loadHS"); witch fixed it, thanks :)
1

You need to use quotes to define a String literal.

test("loadHS");

Without quotes, ActionScript is expecting to find a variable that you've created named loadHS.

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.