Hi DomenicoGemoli, You can establish a connection between creatives, instantiating the LocalConnect component programmatically, implementing the following code (It works for AS2 and AS3, V2 components): //Creating a parent
import com.google.ads.studio.localconnect.LocalConnectParent; var childChannelNames:Array = ["my child"]; var parentConnect:LocalConnectParent =new LocalConnectParent(childChannelNames); parentConnect.connect();
//Creating a child
import com.google.ads.studio.localconnect.LocalConnectChild; var childConnect:LocalConnectChild = new LocalConnectChild("my child"); childConnect.connect();
This way you can establish the connection when you need it. If you want to detect when the creatives has connected use the code below: function conectFunction(e:StudioEvent):void{
trace("Connection established"); }
localConnectComponent.addEventListener(StudioEvent.CONNECT, conectFunction);
Also you can send and receive data between your creatives, using this code: //Send data // Setup: localConnectComponent is the instance name of the Local Connect component on the stage.
import com.google.ads.studio.localconnect.LocalConnectWrapper; var dataObject:Object={message:"Start synced animation!"};
// Send data to all connected components. localConnectComponent.sendData(dataObject);
//Set up listeners to handle sent data:
import com.google.ads.studio.events.StudioEvent; var dataHandler:Function = function(event:StudioEvent):Void {
trace("Message was " + event.data.message);
// If the dataObject referred to in the above "send" example is sent, event.data.message will be "Start synced animation!".
if (event.sender == LocalConnectWrapper.PARENT_NAME && event.data.message == "Start synced animation!") {
trace("Message was sent from the parent");
// Start your synced animation here.
}
};
localConnectComponent.addEventListener(StudioEvent.DATA_RECEIVED,dataHandler);
Regards. |