0

searched whiled but I couldent find the answer here on Stack so I hope someone can help me.

I trying out Flash prof CS6 and Flashbuilder, I have created in Flash a Movieclip called square_mc and instantiated it with the name square.

I have linked a class file called Main.as to FLash builder, and in flash builder I write:

   package
{
    import flash.display.MovieClip;
    import flash.events.MouseEvent;

    public class Main extends MovieClip
    {
        public function Main()
    {
            super();

            circle.addEventListener(MouseEvent.CLICK, onToolClick);
    }

    function onToolClick(event:MouseEvent):void{
        trace("klickade på ontoolclick");
        }

    }
}

in Flash builder I get the warning "access of undefined property circle" But when I run it , it works like a charm.

Im guessing its just that Flashbuilder don't know that I already instantiated it with the name circle in Flash, and therefor gives the warning.

Is there a way I can make Flashbuilder understand that its there and working?

Björn Hjorth
  • 2,459
  • 5
  • 25
  • 31

1 Answers1

0

Option 1: To remedy this, I usually uncheck "Automatically Declare Stage Instance" in the ActionScript Settings (File > ActionScript Settings) in Flash CS6. Then in Flash Builder declare the MovieClip you have on the stage in Flash CS6 as such:

package
{
    import flash.display.MovieClip;
    import flash.events.MouseEvent;

    public class Main extends MovieClip
    {
        public var circle:MovieClip; // manually declare circle

        public function Main()
    {
            super();

            circle.addEventListener(MouseEvent.CLICK, onToolClick);
    }

    function onToolClick(event:MouseEvent):void{
        trace("klickade på ontoolclick");
        }

    }
}

Option 2: If you don't want to manually declare all the movies on the stage, option 2 is to create a reference to circle as a separate variable for Flash Builder:

package
{
    import flash.display.MovieClip;
    import flash.events.MouseEvent;

    public class Main extends MovieClip
    {
        private var _circle:MovieClip;

        public function Main()
    {
            super();
            _circle = this.getChildByName( "circle" ) as MovieClip;
            _circle.addEventListener(MouseEvent.CLICK, onToolClick);
    }

    function onToolClick(event:MouseEvent):void{
        trace("klickade på ontoolclick");
        }

    }
}

This should stop Flash Builder from giving you the error message :)

  • Thanks a lot, googled alitle more on "Automatically Declare Stage Instance" and option 1 seems to be a good answer. – Björn Hjorth Apr 21 '13 at 17:03
  • Btw I see I get the same when I try to get movieclips from the library like "shape = new star_mc();" as it can't find star_mc until runtime. Is there a work around for this as well? – Björn Hjorth Apr 21 '13 at 17:04
  • For linked items like these I would recommend using a SWC file. You can create a library fla with all your linked symbols and check the swc export in Publish Settings. Then reference that swc in Flash Builder and Flash Pro for the current project. Keeps things tidy :) – Jerome Maurey-Delaunay Apr 25 '13 at 11:35