You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, October 19th 2010, 7:00pm

read/update attributes plugin AS3

Hi,

I'm currently modifying the interface example "flashcs3exampleplugin11",
and i don't know where to place my register/update Event and their functions,
syntax seems differents in actual documentation... *confused*

where should i put :

Source code

1
2
3
krpano.addPluginEventListener(this, krpano_as3_interface.PLUGINEVENT_REGISTER, registerEvent);
krpano.addPluginEventListener(this, krpano_as3_interface.PLUGINEVENT_RESIZE,   resizeEvent);
krpano.addPluginEventListener(this, krpano_as3_interface.PLUGINEVENT_UPDATE,   updateEvent);


because Flash throw me errors

first i had this :

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// import krpano as3 interface.as    // 
import krpano_as3_interface;

// create krpano as3 interface object - krpano    
 var krpano:krpano_as3_interface = krpano_as3_interface.getInstance(); 

 // empty functions? - then it wasn't included in the viewer
if (krpano.get == null)
{
	// run plugin swf standalone - no interfaces - add dummy functions
	
	function dummy_get(v:String):String 
	{ 
		if (v != "progress.loaddone")		// avoid progress timer traces
			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;
}

 if (stage)// run standalone
            {
                stage.scaleMode = StageScaleMode.NO_SCALE;// no automatic scaling
                stage.align = StageAlign.TOP_LEFT;// align on top left corner
                startup_plugin(null);
				
            }
            else // run as plugin in krpano
            {
                this.addEventListener(Event.ADDED_TO_STAGE, startup_plugin);
            }
			//
            krpano.call("loadpano(%HTMLPATH%/params.xml,null,KEEPBASE|KEEPPLUGINS,BLEND(1));");


function startup_plugin(event:Event):void
        {
    
		       stage.addEventListener(Event.RESIZE, stage_resize);// setup a global RESIZE event to set the positions of all elements when resizeing
                       stage.addEventListener(FullScreenEvent.FULL_SCREEN, stage_fullscreen_event);// add a Fullscreen event to make changes when switching to fullscreen and back
			//
                      stage_resize(null);// do a first resize
			//
                     get_current_values();
         }

this works fine with no errors,but no attributes reading here....

then after i modify to this :

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// import krpano as3 interface.as    // 
import krpano_as3_interface;

// create krpano as3 interface object - krpano    
 var krpano : krpano_as3_interface = null;

 // empty functions? - then it wasn't included in the viewer
if (krpano.get == null)
{
	// run plugin swf standalone - no interfaces - add dummy functions
	
	function dummy_get(v:String):String 
	{ 
		if (v != "progress.loaddone")		// avoid progress timer traces
			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;
}

 if (stage)// run standalone
            {
                stage.scaleMode = StageScaleMode.NO_SCALE;// no automatic scaling
                stage.align = StageAlign.TOP_LEFT;// align on top left corner
                startup_plugin(null);
				
            }
            else // run as plugin in krpano
            {
                this.addEventListener(Event.ADDED_TO_STAGE, startup_plugin);
            }
			//
            krpano.call("loadpano(%HTMLPATH%/params.xml,null,KEEPBASE|KEEPPLUGINS,BLEND(1));");


function startup_plugin(event:Event):void
        {
                       krpano = krpano_as3_interface.getInstance();
			
			krpano.addPluginEventListener(this, krpano_as3_interface.PLUGINEVENT_REGISTER, registerEvent);
			krpano.addPluginEventListener(this, krpano_as3_interface.PLUGINEVENT_RESIZE,   stage_resize /*resizeEvent*/);
			krpano.addPluginEventListener(this, krpano_as3_interface.PLUGINEVENT_UPDATE,   updateEvent);

		       stage.addEventListener(Event.RESIZE, stage_resize);// setup a global RESIZE event to set the positions of all elements when resizeing
                       stage.addEventListener(FullScreenEvent.FULL_SCREEN, stage_fullscreen_event);// add a Fullscreen event to make changes when switching to fullscreen and back
			//
                      stage_resize(null);// do a first resize
			//
                     get_current_values();
         }

and this time Flash throw me Error #1009 : impossible to access nul object...

what's wrong ??

what is the fix to be able to read/assign/update plugin xml attributes

Thanks *smile*
z

This post has been edited 1 times, last edit by "zadda" (Oct 19th 2010, 8:00pm)


jmulder

Beginner

Posts: 17

Location: Amsterdam, Netherlands

  • Send private message

2

Wednesday, October 20th 2010, 5:43pm

I'm not exactly sure what you're trying to accomplish with your code examples, but you can read/write plugin attributes just fine using the standard interface.

If you look at: http://www.krpano.com/docu/plugins/#register

You'll see a standard method to get a reference to the plugin's instance.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
...

// Register plugin listener
krpano.addPluginEventListener(this, krpano_as3_interface.PLUGINEVENT_REGISTER, registerEvent);

public function registerEvent (e:DataEvent):void {
	// Get plugin data
	p = krpano.get(e.data);

	// Change properties
	p.url  = 'foo';
	p.ahv = 120;
	p.atv = 15;
}

...

3

Wednesday, October 20th 2010, 11:11pm

hi,

when i add

Source code

1
2
// Register plugin listener
krpano.addPluginEventListener(this, krpano_as3_interface.PLUGINEVENT_REGISTER, registerEvent);

somewhere outside a function,
i got a flash error:
TypeError: Error #1006: value is not a function...

and when i put on startup_plugin function, i got Error #1009 : impossible to access nul object...

then i wonder where should i put the code ???

Klaus ?? *confused* (if you got 1 mn in your busy agenda..)

thanks

z

jmulder

Beginner

Posts: 17

Location: Amsterdam, Netherlands

  • Send private message

4

Wednesday, October 27th 2010, 12:08pm

This is the basic template I use and holds all the required event bindings and such:

- registerEvent() is the one that's called when your plugin is registered and ready for use in the Krpano viewer. From this point on the global variable 'p' holds a reference to the plugin instance. Through this you can read or write its data.

- updateEvent() called whenever the data changes (either through your own Flash plugin or through an action in the XML)

- resizeEvent() called when the size changes

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package {
	import flash.display.MovieClip;
	import flash.events.DataEvent;
	import flash.events.Event;
	
	// Import Krpano interface
	import krpano_as3_interface;
	
	public class Main extends MovieClip {
		//
		// Properties
		//

		// Krpano interface
		public var krpano:krpano_as3_interface = null;
		
		// Krpano plugin instance
		private var p:Object = null;

		//
		// Instantiate
		//
		public function Main () {
			if (stage === null) {
				addEventListener(Event.ADDED_TO_STAGE, startPlugin);
				addEventListener(Event.UNLOAD, stopPlugin);
			}
		}
		
		//
		// Start plugin
		//
		public function startPlugin (e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, startPlugin);
			
			// Get Krpano instance
			krpano = krpano_as3_interface.getInstance();
			
			// Register plugin listener
			krpano.addPluginEventListener(this, krpano_as3_interface.PLUGINEVENT_REGISTER, registerEvent);
			krpano.addPluginEventListener(this, krpano_as3_interface.PLUGINEVENT_RESIZE, resizeEvent);
			krpano.addPluginEventListener(this, krpano_as3_interface.PLUGINEVENT_UPDATE, updateEvent);
		}
		
		//
		// Stop plugin
		//
		public function stopPlugin (e:Event):void {
			krpano.removePluginEventListener(this, krpano_as3_interface.PLUGINEVENT_REGISTER, registerEvent);
			krpano.removePluginEventListener(this, krpano_as3_interface.PLUGINEVENT_RESIZE, resizeEvent);
			krpano.removePluginEventListener(this, krpano_as3_interface.PLUGINEVENT_UPDATE, updateEvent);
		}
		
		//
		// Register plugin
		//
		public function registerEvent (e:DataEvent):void {
			// Get plugin data
			p = krpano.get(e.data);
		}
		
		//
		// Resize plugin
		//
		public function resizeEvent (e:DataEvent):void {

		}
		
		//
		// Update plugin
		//
		public function updateEvent (e:DataEvent):void {

		}
	}
}

5

Wednesday, October 27th 2010, 3:12pm

Thanks for replying,

i'm pretty sure your example works fine,
but it wasn't helpful for my case (again some flash errors..aarrrrrrgh *angry* ),

and because i'm not a black belt in action scripting,
i'll be more cumfortable with the .fla source "flashcs3exampleplugin11" modified with the register/resize/update event included,
then i can track down where and why theses errors show up....

again thanks for your patience

z