3 Replies - 1148 Views - Last Post: 08 April 2008 - 12:40 AM

#1 eddieboy665  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 113
  • Joined: 09-April 07

Overlaying sprites that both have actionlisteners

Posted 30 March 2008 - 02:53 PM

Hi again,

I am using Papervision 2 to create a site and have come across an issue where I need two sprites to be ontop of one another and both listen out for clicks... the top one will repond to the click but the bottom one wont. I read flash documentation and don't understand the solution:

Quote

To have a target node's ancestor receive notification of a mouse event, use EventDispatcher.addEventListener() on the ancestor node with the type parameter set to the specific mouse event you want to detect.


I think this applies to me but not sure what it means. Showing the code isn't that easy because its in three different classes but its basically just;
var helperPanel:Sprite = new Sprite();
helperPanel.graphics.beginFill(0x0FF000, 0.2);
helperPanel.graphics.drawRect(0, 0, navMaterial.width, navMaterial.height/2);
helperPanel.graphics.endFill();
helperPanel.addEventListener(MouseEvent.ROLL_OVER, navMovement.onmouseover);
helperPanel.addEventListener(MouseEvent.ROLL_OUT, navMovement.onmouseout);
helperPanel.addEventListener(MouseEvent.MOUSE_DOWN, navMovement.onPress); // problem line
mainApp.addChild(helperPanel);


The transparency is just so that i can see it atm, soon it will be invisible.

If you need more code and explanation as to why and what i'm doing i will happily give it but don't want to spend ages writing it all if there is a simple solution. (I have put up the .swf on a server, version with top click working).

Cheers,
Ed

Is This A Good Question/Topic? 0
  • +

Replies To: Overlaying sprites that both have actionlisteners

#2 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: Overlaying sprites that both have actionlisteners

Posted 01 April 2008 - 02:29 AM

I'm not sure that you can directly do what you want to. You might be better off dispatching events from your top sprite that the bottom one can catch and act on.

Also, using onPress throws a migration warning, but it's not serious and won't stop your code executing.
Was This Post Helpful? 0
  • +
  • -

#3 eddieboy665  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 113
  • Joined: 09-April 07

Re: Overlaying sprites that both have actionlisteners

Posted 02 April 2008 - 12:07 PM

Hi,

Thanks for the reply.

I have the same problem now for another part of my site; if one sprite is on top of another and both need to listen for mouse events, only the top will react to these.

I have tried, as you suggested, dispatching an event but haven't got any response. The code I added:

private function onPress_helperPanel(e:MouseEvent):void
		{
			Sprite(e.target).dispatchEvent(new InteractiveScene3DEvent(InteractiveScene3DEvent.OBJECT_CLICK, navPanel3D));
		}


and the line:
navPanel3D.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, navMovement.onPress_NavPanel);


but this still doesn't work as I was hoping, have you got any suggestions?

I have put two versions that have been updated now online:
Working version but renders the nav panel repeatedly, unnecessarily
With green box that when the mouse moves over it, starts up rendering again

My second problem which is very similar but maybe harder to solve: On the contact page (and others when they are complete) the nav panel, if clicked enough will fly back and go under the content section, I want it to be on top but when I change the contents position index, its all great except you can't fill in the form because the viewport of the nav panel is on top preventing any interaction with the content. If i was to solve this by dispatching events surly I've got loads of events to consider?

Thanks for the help,
Ed
Was This Post Helpful? 0
  • +
  • -

#4 DilutedImage  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 15
  • View blog
  • Posts: 646
  • Joined: 20-November 06

Re: Overlaying sprites that both have actionlisteners

Posted 08 April 2008 - 12:40 AM

To have separate overlapping objects react to the same click, I'd recommend assigning a listener to the stage, and then hit-testing the two objects against the event's x/y coordinates. And not that it'll really make a difference in your situation, but MouseEvent.CLICK is the proper event to listen for.

2
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1