Can we not access the coordinates via their instance name

Post about the Flash World Construction Kit and the Alchemy port of Box2D.
jinisner
Posts: 146
Joined: Tue Apr 17, 2012 12:08 am

Can we not access the coordinates via their instance name

Postby jinisner » Sat Jul 05, 2014 5:10 am

Hi,

I have been trying to reposition a body inside a world to its original position , but some how i cannot seem to do this , only the movieclip seems to move not the body associated with it -


below is the code i am using - the file is here - http://www.fastswf.com/yAnIvBs (when i remove the event listener)

with event listener - http://www.fastswf.com/rpYsIt8

////////========================
stop();

var startXPos:Number = level1WorldObj.box1.x;
var startYPos:Number = level1WorldObj.box1.y;

function areaS(e:Event) {



level1WorldObj.box1.y= startYPos;
level1WorldObj.box1.x= startXPos;
level1WorldObj.box1.removeEventListener(Event.ENTER_FRAME, areaS);


}

but1.addEventListener(MouseEvent.CLICK,nClick3);

function nClick3(event:MouseEvent):void{
level1WorldObj.box1.addEventListener(Event.ENTER_FRAME, areaS);
level1WorldObj.box1.y= startYPos;
level1WorldObj.box1.x= startXPos;
}

Also a most strange behavior seems to be happening the movie clip seems to move but not the body , please see this in debugdraw - http://www.fastswf.com/-Ijkta4

Why am i unable to do it in wck and what i need to do to achieve it ...

Thanks in advance ...

Jin

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Can we not access the coordinates via their instance nam

Postby irresistible force » Sat Jul 05, 2014 10:59 am

I don't see any Box2D code here. Maybe this is a question for the WCK or Flash people.

jinisner
Posts: 146
Joined: Tue Apr 17, 2012 12:08 am

Re: Can we not access the coordinates via their instance nam

Postby jinisner » Sat Jul 05, 2014 11:13 pm

@irrestibleforce - thanks again , that is where i am stuck , i have always used the components that are available to me in the library as wck provides us with option of converting them in to any body we want and give then properties from a property box ....

Now here i have a box that has been given a box shape , and inside the world instance name box1 , so i try and code on the instance name but it seems to not affect the real body ...

I also tried and remove it and add a new box , that works but the new box created does not have properties i want it to have even though i mention it via code , again i use something like -

myWolrd1.box1.type='Static';

if i want it to be static but it does not work , though the original box does seem to have the properties but as i remove it the new box that is dynamically added does not have the properties ...

Thanks again ...

Regards
Jin

jinisner
Posts: 146
Joined: Tue Apr 17, 2012 12:08 am

Re: Can we not access the coordinates via their instance nam

Postby jinisner » Sun Jul 06, 2014 11:27 pm

when i am trying this -

var startXPos:Number= level1WorldObj.box1.b2body.GetPosition().x;

i am getting an error - TypeError: Error #1009: Cannot access a property or method of a null object reference.
at wck::WCK/frame1()[wck.WCK::frame1:3]

what might be wrong here , can you please guide ...

Regards
Jin

jinisner
Posts: 146
Joined: Tue Apr 17, 2012 12:08 am

Re: Can we not access the coordinates via their instance nam

Postby jinisner » Tue Jul 08, 2014 6:45 am

I was able to find solution to this problem , i found the starting point by using this -

trace(level1WorldObj.box1.b2body.GetPosition().x);
trace(level1WorldObj.box1.b2body.GetPosition().y);

then once i had the position manually i took down the coordinates and used the below code ....

level1WorldObj.box1.b2body.SetTransform(new V2(-2, 2),0 );

Thanks @irrestibleforce for all the help ...

Regards
Jin


Return to “WCK”



Who is online

Users browsing this forum: No registered users and 1 guest