Creating a custom action

Post here your questions about the OpenSpace 1.x or notify bugs and suggestions.

Moderators: Lapo, Bax

pt_dev
Posts: 37
Joined: 15 Sep 2008, 16:15

Creating a custom action

Postby pt_dev » 04 Nov 2008, 00:48

I am trying to create a custom action. For example, if an avatar clicks the button, it will do some action.

I know I have to use "onCustomAction" function to make a custom action. However, when I call the MovieClip to play, it give me an error.

Code: Select all

Cannot access a property or method of a null object reference.
   at DummyAvatarMovieClip/onCustomAction()
   at com.smartfoxserver.openspace.mvc::IsoEngineModel/playCustomAvatarAction()
   at com.smartfoxserver.openspace::OpenSpace/setMyAvatarAction()
   at tokiworld_fla::MainTimeline/onActionBtClick()


Do you have any idea what I did wrong?


Thanks alot,

- pt_dev[/code]
daveL
Posts: 10
Joined: 21 Oct 2008, 17:29

Postby daveL » 05 Nov 2008, 00:09

Is the button embedded in another movie clip? If so, did you give it an instance name? If not, did you make sure to check off the 'export for actionscript' in the movie clip's properties?

If yes to both of these, could you please post your code? Maybe I can help out.

-Dave
User avatar
Bax
Site Admin
Posts: 4522
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 05 Nov 2008, 08:34

As reported in the stack trace, it seems that in your onCustomAction() method on the AvatarMovieClip class you are trying to get a property out of a null object. Check every object you are trying to access to find out the one which is null.
Paolo Bax
The SmartFoxServer Team
pt_dev
Posts: 37
Joined: 15 Sep 2008, 16:15

Postby pt_dev » 05 Nov 2008, 17:29

Thank Dave. I've tried but still got an error.

I simply created button and give an event listener.

Here is the button code:

Code: Select all

btn_action.addEventListener(MouseEvent.CLICK, onActionBtClick);


function onActionBtClick(evt:MouseEvent):void
{
   var avatarAction:Object = {}
   avatarAction.id = "testMC"
   
   os.setMyAvatarAction(avatarAction);
}



And I simply created movie clip called "testMC" which display just picture.

Code: Select all

public function onCustomAction(evt:AvatarEvent):void
      {
         var action:Object = evt["params"].action

         if (action != null)
         {
            trace ("'onCustomAction' method called on DummyAvatarMovieClip")
            
            var test:MovieClip = getChildByName("testMC") as MovieClip
            
            trace(test);
            test.visible = true
         }
            
      }


I know I get the Null value for "test". This is a problem which I don't find the problem.

Thank you very much,

- pt_dev
pt_dev
Posts: 37
Joined: 15 Sep 2008, 16:15

Postby pt_dev » 06 Nov 2008, 17:02

Here is a funny thing. I use balloon movieclip and it works fine. I can just display the bubble and I can pass object value. (I am working with the openspace sample files). However, if I create a new movieclip, it didn't work. I got the NULL value. Is there any secret that I have to use to create Movie Clip as a custom action?


- pt_dev
User avatar
Bax
Site Admin
Posts: 4522
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 06 Nov 2008, 17:15

No secrets... there must be something wrong in your code.
When you call getChildByName("testMC") are you sure that you have the testMC movieclip in the root displaylist of your avatar class?
Paolo Bax
The SmartFoxServer Team
pt_dev
Posts: 37
Joined: 15 Sep 2008, 16:15

Postby pt_dev » 11 Nov 2008, 19:12

Hi bax,

Code: Select all

are you sure that you have the testMC movieclip in the root displaylist of your avatar class?


What does it mean by "root displaylist"?

FYI, I used "balloon" movieclip in DummyAvatarMovieClip at AvatarsLievand it worked I've used "highlight" movie clip and it didn't work.

What are the difference these two? let me know and thank you.

- pt_dev
User avatar
Bax
Site Admin
Posts: 4522
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 17 Nov 2008, 08:56

"balloon" is an instance inside the DummyAvatarMovieClip movieclip (which is the "root displaylist" of your avatar).
"highlight" is a movieclip in the library, which must be instantiated before you can access it.
Paolo Bax
The SmartFoxServer Team
pt_dev
Posts: 37
Joined: 15 Sep 2008, 16:15

Postby pt_dev » 17 Nov 2008, 21:28

Thanks for the clarifications. That makes lot of sense.

Anyway, I got it to display the custom action onto the stage now. I need to figure it out how to clear the custom action out when action is done.


However, happy that I can go forward now.


Thanks bax,

pt_dev
danielfck
Posts: 12
Joined: 24 Sep 2009, 03:12
Contact:

Postby danielfck » 24 Sep 2009, 03:23

dear pt_dev and all the AS3 expert,

AS3 is very new for me and i have yet to fully grasp the full understanding.
Bax, i must say that some part in the OpenSpace documentation is very hard to understand and get around. I seriously have to crack my head to figure out how to use all the functions and events implemented in the API. it will be helpful if someone can show MORE and USABLE examples.

right now i'm trying to do the onCustomAction event, so i would appreciate if someone can come to the rescue and enlighten us all noobs.

I will try my best to explain in numbering order of what I am trying to achieve here.

1. i uses 2 files, namely ABC.as and ABC.fla
2. i've created a movieclip of a menu button in the ABC.fla file.
3. this menu button will appear only when the avatar is clicked.
4. this menu button should execute a custom action.
5. the custom action code is reside in the onCustomAction(evt:AvatarEvent), of course.
6. inside the onCustomAction function, i have added the custom actions that i wanted such as jump, swim, etc.
7. this is my BIG question: how do you link that menu button (ABC.fla) to the onCustomAction function (ABC.as) and make the avatar to perform the action?

-end-
User avatar
Bax
Site Admin
Posts: 4522
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 24 Sep 2009, 09:08

Quite simple: when the button is pressed call the OpenSpace.setMyAvatarAction method. This will cause the avatar's onCustomAction method to be called.
Paolo Bax
The SmartFoxServer Team
danielfck
Posts: 12
Joined: 24 Sep 2009, 03:12
Contact:

Postby danielfck » 24 Sep 2009, 09:37

so i will need to put this "os.setMyAvatarAction" code in the OpenSpace map?

if it so, i still don't understand how can the object from setMyAvatarAction can trigger the onCustomAction. how ah?

the thing is:
i am using two *.as files:
one is for the avatar creation -> avatar.as
and the other one is the map creation -> map.as

how is it possible that object A from avatar.as be linked to object B from map.as?
User avatar
Bax
Site Admin
Posts: 4522
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 24 Sep 2009, 09:45

This is up to OpenSpace. If your main application code resides in map.as, there is where you need to call the os.setMyAvatarAction. OpenSpace (which internally creates an instance of avatar.as) will take care of calling the onCustomAction in your avatar.as class.
Paolo Bax
The SmartFoxServer Team
pankajnagarkoti74
Posts: 2
Joined: 29 Sep 2009, 23:10
Contact:

Postby pankajnagarkoti74 » 29 Sep 2009, 23:30

As reported in the stack trace, it seems that in your onCustomAction() method on the AvatarMovieClip class you are trying to get a property out of a null object.

Return to “OpenSpace v1 discussions and help”

Who is online

Users browsing this forum: No registered users and 3 guests