Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

LocalConnection to run a function in another .swf not working....

Explorer ,
Aug 10, 2013 Aug 10, 2013

I'm trying to establish a LocalConnection so that I can communicate between my navbar & the main page on my website. Here is the code I have so far for the sending and receiving AS3 files, please let me know if you see anything out of the ordinary. The idea is that when you click on one of the icons on the navbar my "book" slides down to the center of the screen on the correct page. I actually have 4 buttons but only included the code I'm using for two in order to make this post shorter. The same idea is used for all four buttons though.

Sending:

var sending_lc:LocalConnection;

sending_lc = new LocalConnection();

servicesBtn.buttonMode = true;

portfolioBtn.buttonMode = true;

function servicesBtnOver(event:MouseEvent):void{

servicesBtn.gotoAndPlay('over');

}

function servicesBtnOut(event:MouseEvent):void{

servicesBtn.gotoAndPlay('out');

}

function servicesBtnClick(event:MouseEvent):void{

sending_lc.send("my_lc_as3", "gotoServicesPage");

}

servicesBtn.addEventListener(MouseEvent.ROLL_OVER, servicesBtnOver);

servicesBtn.addEventListener(MouseEvent.ROLL_OUT, servicesBtnOut);

servicesBtn.addEventListener(MouseEvent.CLICK, servicesBtnClick);

function portfolioBtnOver(event:MouseEvent):void{

portfolioBtn.gotoAndPlay('over');

}

function portfolioBtnOut(event:MouseEvent):void{

portfolioBtn.gotoAndPlay('out');

}

function portfolioBtnClick(event:MouseEvent):void{

sending_lc.send("my_lc_as3", "gotoPortfolioPage");

}

portfolioBtn.addEventListener(MouseEvent.ROLL_OVER, portfolioBtnOver);

portfolioBtn.addEventListener(MouseEvent.ROLL_OUT, portfolioBtnOut);

portfolioBtn.addEventListener(MouseEvent.CLICK, portfolioBtnClick);

Receiving:

import com.greensock.*;

import com.greensock.easing.*;

var receiving_lc:LocalConnection;

receiving_lc = new LocalConnection();

receiving_lc.connect("my_lc_as3");

receiving_lc.client = this;

var bookPosition:String = "up";

function gotoServicesPage(event:MouseEvent):void {

     book.gotoAndStop('webDesignPage');

    }

if (bookPosition == "up");

    {

        TweenLite.to(book, 2, {y:830});

          var bookPosition == "down";

    }

}

function gotoPortfolioPage(event:MouseEvent):void{

     book.gotoAndStop('porftolioPage');

if (bookPosition == "up");

    {

        TweenLite.to(book, 2, {y:830});

         var bookPosition == "down";

    }

}

The reason I'm keeping track of whether the book is in the "up" or "down" is so that if it's in the down position already it doesn't re-tween back onto the screen. I am new to declaring and using variables; TweenLite; and LocalConnection so there is probably some simple problem with my AS3 code (although no errors are coming up in Flash). Any help would be much appreciated.

TOPICS
ActionScript
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 20, 2013 Aug 20, 2013

You should output something inslideServicesIn() function to confirm that LC works in principal.

Output trace or create a TextField.

Translate
LEGEND ,
Aug 11, 2013 Aug 11, 2013

To begin with you have several severe syntax issues in receiving code. The code it is shown should not even compile.

gotoServicesPage has extra internal curly bracket, conditionals should not have semicolons at the end of the line.

Use strict mode to see compiler errors.

Also, you declare bookPosition as a new variable every time. Looks like you need to reuse bookPosition you declared in the higher scope.

Fix these issues and see if things fall in place.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 19, 2013 Aug 19, 2013

Alright I'm going to fix one problem at a time, starting with the LocalConnection. I've checked several websites for tutorials and examples but cannot seem to get it working properly. I'm just trying to run a simple function over it and can't get it working. Once I can get it working, I'll modify the rest of the code to do what I need. Right now I'm just trying to use it to run a function (slideServicesIn) in a seperate swf. file. I've checked and rechecked the code and just can't figure out why it's not working.

Here's the sending code:

import flash.net.LocalConnection;

import flash.events.MouseEvent;

var lc:LocalConnection = new LocalConnection();

function servicesBtnClick(event:MouseEvent):void{

lc.send("my_lc_as3","slideServicesIn");

}

servicesBtn.addEventListener(MouseEvent.CLICK, servicesBtnClick);

Looks pretty simple.... And here's the receiving code:

import flash.net.LocalConnection;

var lc:LocalConnection = new LocalConnection();

lc.connect("my_lc_as3");

/*If you're not familiar with TweenLite or TweenMax, I can revise the code. I can't get it to work even just to go to a certain frame label. This seems pretty basic if you are even a little familiar with TweenLite/Tweenmax*/

import com.greensock.*;

import com.greensock.easing.*;

import com.greensock.plugins.*;

var bookPosition:String = "up";

var currentPage:String;

function slideServicesIn ():void{

      

         if (bookPosition = "up"){

        

         //Goes to a certain frame label in the book movie clip

         book.gotoAndStop("webDesignPage");

         //Slides the book down 825px from the top of the screen using TweenLite

         TweenLite.to(book, 3, { y:825 } );

         bookPosition = "down";

         currentPage = "book.servicesPage";

        }

   

        else () {

         //Fades out the current page using TweenLite

         TweenLite.to(currentPage, 1, { alpha:0, ease:Quad.easeIn } );

         //Fades in the Web Design Page using Tweenlite

         TweenLite.to(book.webDesignPage, 1, { alpha:1, ease:Quad.easeIn, delay: .2 } );

        }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 20, 2013 Aug 20, 2013

You should output something inslideServicesIn() function to confirm that LC works in principal.

Output trace or create a TextField.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 20, 2013 Aug 20, 2013

I tried to use trace in slideServicesIn() and got this error:

Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.LocalConnection was unable to invoke callback slideServicesIn. error=ReferenceError: Error #1069: Property slideServicesIn not found on flash.net.LocalConnection and there is no default value.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 06, 2013 Sep 06, 2013
LATEST

One dumb little line of code is all it took.

conn.client=this;

It's not listed as necessary in Adobe's example page. I saw it in a code elsewhere while looking around. Anyone else that's having this problem here is the simple code that you can use to communicate between two swfs loaded on the same page:

receiving as3 code:

var conn:LocalConnection;

conn = new LocalConnection();

conn.connect('myConnection');

conn.client=this;

sending as3 code:

var conn:LocalConnection = new LocalConnection();

// this will execute the slideServicesIn function in the receiving swf *AWESOME!*

function servicesBtnClick(event:MouseEvent):void{

conn.send('myConnection','slideServicesIn');

}

It took me quite a while to figure it all out and am hoping this will save someone like me many hours of searching in the future.

I read you can do two way communication using LocalConnection also but the connection names need to be different for sending & receiving. For instance connReceiving, and connSending (and possibly myIncommingConnection, and myOutgoingConnection, not sure cause I haven't tested it).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines