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:
- Call to a possibly undefined method
createName through a reference with
static type Class. – (update) I forgot to make the method static. - 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?
For second problem, try
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.