ambiera home ambiera home

Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name:  Password:    
Ambiera Forum > CopperCube
Using 2d overlay items as buttons in actionscript
Author Text

hupie
Registered User
Quote
2011-03-22 14:26:20

Hey,

I want to add 2d buttons to my 3d scene and code them in actionscript but i cant get it to work.

-When i draw rectangle's on the Flash Stage on a new layer, they show up for a split second when i test the movie and then gets overlayed with the 3d scene immediately after. So i cant add buttons this way.

-When i make 2d overlay items in CC editor i have trouble calling them. I tried this code (using the template code found in the docs http://www.ambiera.com/coppercube/doc/index.html )

		// called when the coppercube .swf file has been loaded and initialized
private function onCoppercubeLoaded(e:Event):void
{
// get access to the simple API object:
coppercubeSprite = loader.content as DisplayObject;
simpleAPI = coppercubeSprite['simpleAPI'];

stage.addEventListener(KeyboardEvent.KEY_DOWN, aKeyDown);
addEventListener(Event.ENTER_FRAME,frameLoop);

// code below doesnt work
var button:Object = simpleAPI.getSceneNodeByName("button");
button.addEventListener(MouseEvent.CLICK, );



}

But then i get this error
TypeError: Error 1009: Cannot access a property or method of a null object reference.
at main/onCoppercubeLoaded()


So how do i get working 2d buttons?


kingkohle
Registered User
Quote
2011-03-22 15:49:16

What exactly are you trying to do? You could set up the 2D overlays in CC and script them with JavaScript (to suit special needs). When you publish it, it seems that they are getting translated into AS automatically..

Sorry Im not too familiar with AS. Actually you can do a lot when applying actions to 2D overlays (in CC), so it depends what you are trying to do..


hupie
Registered User
Quote
2011-03-22 16:23:22

I just want simple buttons which trigger custom AS3 functions.

Say i have a forward and backward button and it moves the camera smoothly between 5 or so predefined camera positions (in order). I know this can be done in CC with the action/behavior menu's but i think this will be a rather slow and tedious process (lots of repetitive clicking) and once i master AS3 a little bit more, this will be prob be a lot more efficient when done code wise i think.

I have zero knowledge on javascript unfortunately, i just watched some AS3 vid tutorials and Papervision vid tutorials so thats all i know about programming. Thats why i prefer to stay in AS.


niko
Moderator
Quote
2011-03-22 16:32:57

Are you using Molehill? I know there is a bug in the flash player which causes 2d stuff to disappear. The trick I'm using to prevent this is to compile the flash swf to a size like for example for 200x200, and then resize it in the website to something like 320x220. Then it reappears.


hupie
Registered User
Quote
2011-03-22 16:53:09

No i'm not using Molehill. I just have a lack of knowledge on AS3 and Flash and programming experience. Unfortunately there aren't many step by step CC tutorials which explain how to use the API (not blaming anyone here).

Maybe i have to spend some time exploring other flash engines beginner tutorials so i understand the simpleAPI and actionscript better.


niko
Moderator
Quote
2011-03-22 18:00:32

There are are even two tutorials, for example this one here: http://www.ambiera.com/coppercub...
Also there is an example in the beginning of the reference: http://www.ambiera.com/coppercub...
But true, it assumes you have some Actionscript experience.


hupie
Registered User
Quote
2011-03-25 13:10:51

I still haven't managed to get a button to work.

In the constructor function i add an eventlistener for the mouse:
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseIsDown);

This function is getting called:

public function mouseIsDown(e:MouseEvent):void
{
var button:Object = simpleAPI.getSceneNodeByName("button");

if (e.target == button) trace("button clicked");

}


My main problem is to add a mouse down event listener to the button (a 2ddisplayobject made in CC). How do i pull this off?


niko
Moderator
Quote
2011-03-25 16:57:40

Ah, I thought you are creating buttons in flash to overlay them over the 3d scene from CopperCube. That would have been worked. Connecting them the way above doesn't work, I'm sorry. The only thing I guess this would be possible, is to set a variable using a behavior in the editor when the button is pressed, and check every frame using Actionscript if the variable is set.


hupie
Registered User
Quote
2011-03-28 10:54:09

Ok thanks for your answer niko.

I guess this is the same for 3d objects? E.g. i can't call them directly from actionscript with eventlisteners but i can only use them through setting variables in CC and then check those variables every frame in AS?


niko
Moderator
Quote
2011-03-28 17:04:18

No, eventlisteners not, I'm sorry. But it's a good idea, maybe I'll add something like this in the near future.


hupie
Registered User
Quote
2011-04-01 11:06:52

I tried using the method u suggested Niko but I don't know how i can reach variables made in CC from actionscript. Currently i set the variable 'current_view' (valuetype = value) when a 2d overlay item is clicked. The variable works fine within CC editor, but how can i reach it from AS3?

I tried declaring the variable in the main class and trace it when a key is pressed but it gives me this error

[Fault] exception, information=ArgumentError: Error 1063: Argument count mismatch on Main/keyDown(). Expected 0, got 1.

Also simpleAPI.current_view doesn't work (was a long shot anyways ;) )

Is it possible to reach CC editor variables from AS?


niko
Moderator
Quote
2011-04-01 11:58:30

Use the getCopperCubeVariable() call in the SimpleAPI, as described here (scroll a bit down): http://www.ambiera.com/coppercub...


hupie
Registered User
Quote
2011-04-01 13:40:59

Hmm i cant get the get getCopperCubeVariable() call to work :(. Maybe im doing something wrong but when i try this:

trace(simpleAPI.getCopperCubeVariable('current_view'));

I get:

[Fault] exception, information=ArgumentError: Error 1063: Argument count mismatch on Main/keyDown(). Expected 0, got 1.

Also the get and setCopperCubeVariable method isn't described yet in the online docs, u might want to put it there as well ;).


niko
Moderator
Quote
2011-04-01 13:56:34

hm, the exception you write seems to be caused by your code, something in your keyDown()-function.
Online docs updated. :)


hupie
Registered User
Quote
2011-04-01 14:19:32

Yes you are right, i forgot to put the e:keyboardevent in the argument. Stupid mistake, even for an artist like me ;).

Still, it doesnt work quite yet because trace returns 'null' instead of a certain value. In CC editor i set the variable current_view to 2 when a 2d overlay item is clicked so i should trace 2 as well, but i get null . The click behavior is triggered however cause when i set the action to move the camera, it does perform that action after the compilation in Flash Develop.


Create reply:


Posted by: (you are not logged in)


Please enter the missing letter in: "Internationa?" (you are not logged in)


Text:

 

  

Forum Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   





Software: Ambiera Light Forum. © 2008-2013 Nikolaus Gebhardt, Ambiera e.U.