Wednesday, 15 July 2015

flex - calling the component from within the script -



flex - calling the component from within the script -

i have component , want phone call within script section.

so instead of getting this:

<s:application> <script> </script <ns1:msns includein="login" x="482" y="541"> </ns1:msns> </s:application>

i want have this:

<s:application> <script> protected function mmshakkoutab(event:mouseevent):void { var ns1:msns:component = new component(); ns1:msns.x = 5 ns1:msns.x = 5 } </script </s:application>

is possible? have searched around examples give me component in place under script.

if understand properly, yes, possible. you're terminology of "call component" non-standard; think want create component in actionscript instead of mxml. can mxml can actionscript.

you have right idea; , you're of way there; there few things change. first, in actionscript import class; wouldn't reference mxml namespace, conceptually this:

import com.mypackage.msns;

in script block.

when create component, want create variable points it. correspond id field in mxml. syntax of ns1:msns:component cause compiler errors. but, can create component this:

var msns :component = new component()

i'll mention here usual convention capitalize component names. utilize of lowercase not syntactically wrong, though.

then set properties on component, you're doing:

msns.x = 5 msns.x = 5

and finally--this step you're missing--you must add together new component container. can addelement if you're dealing spark containers or addchild if you're dealing mx containers. since, in illustration provided you're parent container spark application, i'll utilize addelement:

this.addelement(msns);

so, you're code block re-written this:

protected function mmshakkoutab(event:mouseevent):void{ var msns:component = new component(); msns.x = 5 msns.x = 5 this.addelement(msns); }

one thing should consider reading on flex component lifecycle. every flex component goes through it; , things done in order purpose. creating children may improve off extending createchildren(), if want component created part of initial setup of application tag.

flex custom-component

No comments:

Post a Comment