Ambiera ForumDiscussions, Help and Support. |
|
[ 1 2 ] Page 1 of 2 |
|
|||||
|
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 But then i get this error TypeError: Error 1009: Cannot access a property or method of a null object reference. So how do i get working 2d buttons? |
||||
|
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.. |
||||
|
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. |
||||
|
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. |
||||
|
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. |
||||
|
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. |
||||
|
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:
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? |
||||
|
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. |
||||
|
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? |
||||
|
No, eventlisteners not, I'm sorry. But it's a good idea, maybe I'll add something like this in the near future. |
||||
|
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? |
||||
|
Use the getCopperCubeVariable() call in the SimpleAPI, as described here (scroll a bit down): http://www.ambiera.com/coppercub... |
||||
|
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 ;). |
||||
|
hm, the exception you write seems to be caused by your code, something in your keyDown()-function. Online docs updated. :) |
||||
|
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. |
[ 1 2 ] Page 1 of 2 |
|