开发者

Can't pass data from child to child

I have a parent and 2 children. I am trying to pass data from child1 to child2 but keep getting an error message: 1061: Call to a possibly undefined method through a reference with a static type.

In child1 I have the following code:

[Bindable]
public var TestVar:String='sometext';

In child2 I am trying to get the value of TestVar and then use it as a value to search a mysql data开发者_运维百科base via php.:

  var newTestVar:String = child1.TestVar;
  if(newTestVar != null){
    getResult.token = someService.get_filtered_Paged(newTestVar);
  }

  else{
    getSecResult.token = someService.get_paged(); 
  }


@ape is right, you should make is Static or use MVC to inject the property.


change public var TestVar:String='sometext'; to public static var TestVar:String='sometext'; You are getting this error because you are trying to access the variable: TestVar in a static context when you have not marked it static.


You're getting this error because you declared child1 as a superclass of whatever child1 actually is. It's only natural that TestVar is not defined there. To top it off that superclass is not dynamic so you'd need to access that field with:

child1["TestVar"];

That will not generate a compile error, and should have no problem accessing the field at runtime if the instance held by child1 is the right one.


Let's say you defined TestVar in MyClass1. Cast child1 to that type:

var newTestVar:String = MyClass1(child1).TestVar;

If this does not help, please post bigger part of your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜