That did work, thanks very much.
But I have a slightly different case that I can't seem to fit to your
solution.
I actually want to call this from MicrophoneClass.as, from within an
event handler:
public function activityHandler(event:ActivityEvent):void
{
...
}
If I use the approach you suggested:
var main:Main = new Main();
main.createSprite(this);
Then I get this error:
Implicit coercion of a value of type MicrophoneClass to an unrelated
type mx.core:UIComponent
And I understand the error, but I can't seem to fix it. I'm still
having trouble understanding displaylist and how to add children to
them.
Thanks for any help,
Jon
--- In [email protected], yigit <[EMAIL PROTECTED]> wrote:
>
> the reason is that your main.as does not have a valid view.
> try passing the mxml view as an argument to it and call it's addChild
> function;
> e.g.
> public function createSprite2():void{
> var main:Main = new Main();
> main.createSprite(this);
> }
>
> and in main.as
>
> public function createSprite(con:UIComponent) : void{
> var visual:Visual = new Visual();
> var ref:UIComponent = new UIComponent();
> con.addChild(ref);
> ref.addChild(visual);
> trace('called from Main.as');
> }
>
> and it should work...
>
>
>
>
>
> jrag0n wrote On 01/21/2008 08:30 AM:
> >
> > Hello,
> >
> > When I try to draw a circle on the screen by calling a script that's
> > in the mxml, it works
> > fine:
> >
> > <mx:Button label="Button" click="createSprite1();" right="10"
top="10"/>
> > and
> > public function createSprite1():void
> > {
> > var visual:Visual = new Visual();
> > var ref:UIComponent = new UIComponent();
> > addChild(ref);
> > ref.addChild(visual);
> > trace('called from mxml');
> > }
> >
> > But if I try to call it from a class, it is called (I can tell
because
> > of the trace output) but it
> > doesn't draw the circle on the screen.
> >
> > Here's my rough code that doesn't work so far:
> >
> > <mx:Button label="Button" click="createSprite2();" right="10"
top="40"/>
> > public function createSprite2():void
> > {
> > var main:Main = new Main();
> > main.createSprite();
> > }
> >
> > And then my Main.as file just has the same code:
> >
> > public function createSprite() : void
> > {
> > var visual:Visual = new Visual();
> > var ref:UIComponent = new UIComponent();
> > addChild(ref);
> > ref.addChild(visual);
> > trace('called from Main.as');
> > }
> >
> > As I said, I know this class is being called because I can see the
> > trace output. Any
> > suggestions why this isn't working for me?
> >
> > Thanks for any help,
> > Jon
> >
> >
>