Page 1 of 1
Creating a custom action
Posted: 04 Nov 2008, 00:48
by pt_dev
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]
Posted: 05 Nov 2008, 00:09
by daveL
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
Posted: 05 Nov 2008, 08:34
by Bax
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.
Posted: 05 Nov 2008, 17:29
by pt_dev
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
Posted: 06 Nov 2008, 17:02
by pt_dev
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
Posted: 06 Nov 2008, 17:15
by Bax
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?
Posted: 11 Nov 2008, 19:12
by pt_dev
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
Posted: 17 Nov 2008, 08:56
by Bax
"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.
Posted: 17 Nov 2008, 21:28
by pt_dev
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
Posted: 24 Sep 2009, 03:23
by danielfck
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-
Posted: 24 Sep 2009, 09:08
by Bax
Quite simple: when the button is pressed call the
OpenSpace.setMyAvatarAction method. This will cause the avatar's
onCustomAction method to be called.
Posted: 24 Sep 2009, 09:37
by danielfck
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?
Posted: 24 Sep 2009, 09:45
by Bax
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.
Posted: 29 Sep 2009, 23:30
by pankajnagarkoti74
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.