Flash-JS-VK-Api-Bridge -intermediary for Flash applications built into iframe. The use of this intermediary makes it possible to contact the methods of API social. VKontakte networks from AS3.
An example of an application using this intermediary ==> https://vk.com/app6213458
The advantages of work through this intermediary:
Short description: The principle of the intermediary is built on the call of the JS Flash and vice versa function. This is achieved due to the methods of the Externalinterface class. In turn, JS interact with JavaScript SDK , which is provided by the social network. In the HTML, the object-Flash page is integrated by SWFOBject.
Connect the necessary classes to your project:
//as code
import ExternalFlash.APIConnection ;
import ExternalFlash.events.CustomEvent ;If you also need to create buttons, with the style of the social network, do not forget to connect this class:
//as code
import ExternalFlash.ui.VKButton Create a copy of the Apiconnction class, check if the intermediary is ready to work. If the intermediary is not yet ready, subscribe to the CustomEvent.on_ei_init_end event. Start working with an intermediary only after he is ready to work. Otherwise, it may not work correctly.
An example of creating an instance, with a check for initialization:
//as code
//Создаем экземпляр класса APIConnection
_VK = new APIConnection() ;
//Перед тем, как делать запросы, добавлять слушатели и т.д. Необходимо обязательно убедится, что посредник уже инициализировался.
//Иначе, посредник будет работать некорректно. Информация о инициализации может быть трех типов:
if ( _VK . eiConnectStatus == "WORKING" ){
//Посредник инциализировался, все работает. Только теперь можем работать с API
//Тут можно вызывать функцию, которая начнет работать с методами API
} else if ( _VK . eiConnectStatus == "NOT_WORK" ){
//Посредник не работает по какой либо причине.Это окончательный статус, он не изменится. Причина непоказывается, но если вы захотите сделать ее вывод, Вы можете посмотреть в классе ExtIntClass список причин, и выводить их оттуда
} else if ( _VK . eiConnectStatus == "CONNECTION" ){
//Посредник еще не загрузился. В этом случае надо поставить слушатель на экз. класса и слушать событие CustomEvent.ON_EI_INIT_END
//Событие приходит вместе с параметром connectState. Может быть WORKING - значить посредник инициализировался. NOT_WORK - посредник не будет работать.
_VK.addEventListener(CustomEvent.ON_EI_INIT_END, function (event:CustomEvent){
if (event . params . connectState == "WORKING" ){
//Посредник инциализировался, все работает. Только теперь можем работать с API
//Тут можно вызывать функцию, которая начнет работать с методами API
} else {
//Посредник не работает
}
_VK . removeEventListener (CustomEvent . ON_EI_INIT_END , arguments . callee ) ;
})
}The status of the connection _vk.eiconnecttatus can be three types:
The parameters of the event CustomEvent.on_ei_init_end:
This event can occur only once - in initialization. Therefore, you do not need to listen to it, except in this case.
The data obtained when the application launches is transmitted to Flash via Flashvars . You can also get them, as when using Flash SDK.
//as code
var _flashVars : Object = stage . loaderInfo . parameters as Object ;These parameters will be available immediately after launching the application. To use them, it is not necessary to wait for the initial of the intermediary.
All the names of the methods that were used in the provided social. The Flash SDK network is the same as used in this intermediary. Thus, when moving with Flash SDK, working with a specimen of this intermediary will happen the same.
What needs to be taken into account at the transition:
//js code
} , '5.68' ) ; //string 9This will probably solve the problem of not correct operation of the application, and there will be no need to change the names/arguments of the API methods in it.
There are a lot of comments in the code - this is in case someone wants to understand how this mediator works, how initialization occurs and more.
In any case, to understand how it works from the inside, you can not download sources and use them to your project, without studying the device of the intermediary.