更新一个变种,它从另一个组件得到的是它的价值 [英] Update a var, which get's it it's value from another component
问题描述
我无法与更新变种和射击的creationComplete功能吧。
I'm having trouble with updating a var and firing a function with it on creationcomplete.
在主要成分我宣布一个变种艺术家。这个VAR肯定工作,并具有一个值。我还需要一个变种在另一个组件:一个配置文件的组成部分。我能够得到的VAR有:
In the main component i declared a var artist. This var certainly works and has a value. I also need that var in another component: a profile component. I am able to get that var with:
newVar = Maincomp(this.parentApplication).artist;
我用的是newVar在配置文件组件的API。当我启动的API函数的MouseEvent,它的工作原理。但是,我要启动的API函数的creationComplete,比VAR不起作用:它返回null。我希望让所有的参与瓦尔绑定会有所帮助,但事实并非如此。这怎么能解决吗?
I use the newVar in an API in the profile component. When i launch the API function with a mouseEvent, it works. However, i want to launch the API function on creationComplete and than the var doesn't work: it returns Null. I hoped that making all the involved vars bindable would help, but it doesn't. How can this be fixed?
额外code来说明这个问题:
Extra code to make my case clearer:
在主要排版:
public function handleclick(cName:String):void
{
vName = "aVariableIGetFromAnAPI";
}
在轮廓补偿:
public function zoekImages(event:FlexEvent):void
{
var api_URL:String = 'http://ws.audioscrobbler.com/2.0/';
var api_imagemethod:String = 'artist.getImages';
var api_key:String = '99f1f497c0bd598f1ec20571a38e2219';
artistImage = DifficultierAPI(this.parentApplication).vName;
var autocorrect:String = '1';
var limit:String = '4';
api_imagerequest = api_URL + '?method=' + api_imagemethod + '&artist=' + artistImage + '&autocorrect=' + autocorrect + '&api_key=' + api_key + '&limit=' + limit;
imageRequest.send(); // hier maak je connectie met lastfm
}
这code工作,但问题是,这个code的作品,如果我把它带的MouseEvent,但不会当它需要发动对的creationComplete。或者不好,它会返回NULL,而不是值。我认为,让涉及的增值经销商可绑定将修复它,但它没有。任何帮助?
This code works, but point is that this code works if i call it with a MouseEvent, but doesn't when it needs to launch on creationcomplete. Or well, it returns Null instead of a value. I thought that making the involved vars bindable would fix it, but it doesn't. Any help?
推荐答案
如果你正在寻找变量一直从主应用程序到嵌套组件绑定,只需声明一个变量作为组件内的公共和绑定:
If you're looking to bind the variable all along from the main application to the nested component, simply declare a variable as public and bindable within your component :
主要适用
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:Components="Components.*">
<fx:Script>
<![CDATA[
[Bindable]
public var myMainVar:String;
protected function button1_clickHandler(event:MouseEvent):void
{
myMainVar = "Hi there!";
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:Button label="Click me to update the coponent's variable" click="button1_clickHandler(event)"/>
<Components:MyCustomComponent myComponentVar="{myMainVar}"/>
</s:WindowedApplication>
嵌套组件
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
[Bindable]
public var myComponentVar:String;
]]>
</fx:Script>
<s:Label text="{myComponentVar}"/>
</s:Group>
我希望这是你在找什么: - )
I hope it is what you're looking for :-)
这篇关于更新一个变种,它从另一个组件得到的是它的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!