1 Reply Latest reply on Nov 12, 2014 4:07 PM by Sean_Wilson

    newproxycallback question

    bluelemonade Level 1



      inside a flash sprite behaviour I initialize my callback


      on beginssprite me

      pCB = sprite(me.spriteNum).newProxyCallback(#sendToLingo)

      sprite(me.spriteNum).stage.getChildAt(0).addEventListener("sendToLingo", pCB)



      -- this function is called from the flash.

      on sendToLingo me, evt


           put "Data received from AS3:" && evt.data





      inside flash I have a class to get some values via tcpip, this works fine...

      I add an ondataArravied eventlistener to rhis object.




      that calls the method


      function onDataArrived(e:Event){


      trace("onDataArrived " + getTimer() );

      comInAry = com_pci.data;


      var tempPos:String = (comInAry[0]).toString();


      if (tempPos != currSlidePos) {

          trace("onDataArrived and changed" + getTimer() );

          dispatchEvent( new LingoEvent("slidePos:" + currSlidePos) );






      OK, when I onDataarrived is called one, I get a bunch of events in director, every time the tempPos != currSlidePos I get 20 or 30 times the sendToLingo

      event in director. why, the trace inside flash is only fired once...


      would be nice to get some help.



        • 1. Re: newproxycallback question
          Sean_Wilson Adobe Community Professional

          You should wait until your flash sprite has initialised before setting up communications. Something like the following typed as a #parent script and named "init" in your castLib:

          -- parent script "init"
          on enterFrame me
            sendSprite(me.spriteNum, #init)


          and attached to the Flash sprite:

          property spriteNum
          property my
          property ancestor
          on beginSprite me
            my = sprite(spriteNum)
            ancestor = script("init").new()
          on init me
            ancestor = VOID
            cb = my.newProxyCallback(#sendToLingo)
            my.stage.getChildAt(0).addEventListener("sendToLingo", cb)
          -- etc.


          This will force the Flash sprite to wait for one frame cycle before setting up.