hi, im making plugin problem with event

  • Hi, okay I will try to explain how to develop plugins:

    first copy the krpano_as3_interface.as to your flash project folder,

    and import it:

    Code
    import krpano_as3_interface;

    then you should add a Listeners for waiting until the plugin was added to the stage:
    (also add the a remove event to clean everything of the plugin)

    Code
    if (stage == null)
    {
        // plugin startup
        addEventListener(Event.ADDED_TO_STAGE, startplugin);
        addEventListener(Event.REMOVED_FROM_STAGE, stopplugin);
    }

    then it's time to get a interface to krpano,
    create a variable of the krpano_as_interface class and
    call the static getInstance() function to get a interface object:

    Code
    var krpano : krpano_as3_interface = null;
    
    
    function startplugin(event:Event):void
    {
        krpano = krpano_as3_interface.getInstance();
    }

    with this krpano_as3_interface object you can access all krpano objects or data from the xml file with it,
    e.g. if you want to change this view settings - get the whole view object:

    Code
    var view:Object = krpano.get("view");
    view.hlookat += 10.0;

    or you can also get/set each attribute with set and get:

    Code
    var hlookat:Number = krpano.get("view.hlookat");
    krpano.set("view.hlookat", hlookat + 10 );

    but the first method is recommended, using krpano.get / krpano.set is slow!

    everything clear for the moment?

  • I continue with - how to access to the plugin itself:

    if you know the "name" of the plugin,
    this name:

    Code
    <plugin name="pluginname" .... />

    you can just use:

    Code
    var pluginobject:Object = krpano.get("plugin[pluginname]");

    to get a object to access all attributes of the plugin,

    if the name is not fixed (the common case) add a a special "register plugin" event listener to get the path/name of the plugin:

    Code
    krpano.addPluginEventListener(this, krpano_as3_interface.PLUGINEVENT_REGISTER, registerEvent);

    this event is dispatched from krpano after loading to the plugin, krpano passes a "DataEvent" Object with the name/path of the plugin:

    Code
    function registerEvent(evt:DataEvent):void
    {
        var pluginpath:String   = evt.data;
        var pluginobject:Object = krpano.get(pluginpath);
    }

    now you can read the attributes of the plugin,
    or add attributes or function,

    e.g. - to add a function that can be called from XML or from a other plugin - just do this:

    to access this function from XML, e.g. on a hotspot click:

    Code
    <hotspot .... onclick="plugin[pluginname].myfunction();" />

    any questions for the moment?

  • hi, klaus, first a lot of thanks for the explanation, i've solved for a while the problem begin of how to detect the event of ipdate plugin by attribute, the prioblem begin of how to detect the atrribute i've use the tutorial example, but only works width tahis.
    krpano.get("plugin[pluginname]");
    thanks sure great work.

  • Hi,

    I've one question :

    Why do we have a if condition her ?

    Code
    if (stage == null)
    {
        // plugin startup
        addEventListener(Event.ADDED_TO_STAGE, startplugin);
        addEventListener(Event.REMOVED_FROM_STAGE, stopplugin);
    }

    What does it mean, to be on the stage or not, for the plug-in ?

    If we call it, it can be somewhere else than the stage ?

    Thanks for the answer,

  • Hi,

    when stage == null the plugin was started from krpano, and the plugin can use getInstance() to
    get access to krpano,

    but when stage is set - the plugin was started standalone, and access to krpano will fail,

    in my plugins I used this to show the version number of the plugin, when starting it standalone,

    best regards,
    Klaus

  • Hi,

    what would be like the stopplugin function? *whistling*

    in stopplugin function, all from the plugin added elements and events should be removed,

    i used this lines of code, but i get this error:

    you can show the code in it's context?
    has the "krpano" object a value? (not 'null')
    was "krpano_as3_interface.getInstance()" called before?
    is the plugin running inside krpano?

    best regards,
    Klaus

  • here it is:

    Code
    import krpano_as3_interface;
    var krpano:krpano_as3_interface = krpano_as3_interface.getInstance();//var view:Object = krpano.get("view");
    if (krpano.get == null){// run plugin swf standalone - no interfaces - add dummy functions
    function dummy_get(v:String):String{if (v != "progress.loaddone"){trace("get(" + v + ");");}return "";}function dummy_set(v:String,val:String):void{trace("set("+v+","+val+");");}
    function dummy_call(action:String):void{trace("call("+action+");");}
    krpano.get = dummy_get;krpano.set = dummy_set;krpano.call = dummy_call;}
    krpano.set("plugin[GUI].autopos", "center,0,0");krpano.set("fullscreen", true);krpano.set("control.mousetype", "moveto");krpano.set("control.movetocursor", "arrow");//view.hlookat = 10;

    this block of code works fine, but i want to use Object method you mentioned above.

    I wish my Blood was Blue

    S.M.Taheri


  • I use this block of code but i got this error:

    Quote

    1120: Access of undefined property pluginobject.

    Quote

    pluginobject.myfunction = plugin_test_hello;

    I wish my Blood was Blue

    S.M.Taheri

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!