0

I have two MXML component files and try to work with them as classes. One of them has a simple function:

GUIFriend.mxml

<mx:Script>
    <![CDATA[           
        public function createName(f:Friend) {
            return 'friendProfile: ' + f.uid;
        }
    ]]>
</mx:Script>

And the other tries to use it:

GUIFriendContainer.mxml

<mx:Script>
    <![CDATA[

        import GUIFriend;

        public function getFriendProfile(f:Friend):GUIFriend {
            var result:DisplayObject = getChildByName(GUIFriend.createName(f));
            if (result is GUIFriend) {
                return result;
            } else {
                // TODO: throw error
                return null;
            }
        }           
    ]]>
</mx:Script>

But in the line that references 'createName' function I get two errors:

  1. Call to a possibly undefined method createName through a reference with static type Class. - (update) I forgot to make the method static.
  2. Implicit coercion of a value with static type flash.display:DisplayObject to a possibly unrelated type GUIFriend.

But I see no rational reason for it. What's wrong with my code?

2 Answers 2

2

For second problem, try

var result:DisplayObject = getChildByName(GUIFriend.createName(f)) as DisplayObject;

if you still have problems, temporarily type result as Object and put in a debug breakpoint to check what is really coming back from the getChildByName call.

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

Comments

1

You're trying to call an instance method directly through the class name.

You either need to make the method static or create an instance of the class and call the method on that.

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.