-
1. Re: Problem with events and Movieclips
kglad Sep 6, 2013 11:37 PM (in response to vari25)what code executes when that button is clicked?
-
2. Re: Problem with events and Movieclips
vari25 Sep 7, 2013 12:19 AM (in response to kglad)Hi,
I have this for every button and a mouse event and key event and zoom event added.
Below is the button function:
garage_horizon_btn.addEventListener(MouseEvent.CLICK,garage)
function garage(event:MouseEvent):void
{
garage_horizon_mc.gotoAndStop(rotationframe);
garage_horizon_mc.visible=true;
garage_horizon_mc.stop();
garage_moss_mc.visible=false;
garage_ocean_mc.visible=false;
gutter_ocean_mc.visible=false;
gutter_horizon_mc.visible=false;
gutter_moss_mc.visible=false;
main_mc.visible=false;
}
Mouseevent:
var rotater_gah:MovieClip = garage_horizon_mc;
var offsetFrame_gah:int = rotater_gah.currentFrame;
var offsetX_gah:Number = 0;
var percent_gah:Number = 0;rotater_gah.addEventListener(MouseEvent.MOUSE_DOWN,startDragging_gah);
rotater_gah.addEventListener(MouseEvent.MOUSE_UP,stopDragging_gah);function startDragging_gah(e:MouseEvent):void
{
rotater_gah.addEventListener(MouseEvent.MOUSE_MOVE,drag_gah);
offsetX_gah = e.target.mouseX;
}function stopDragging_gah(e:MouseEvent):void
{
rotater_gah.removeEventListener(MouseEvent.MOUSE_MOVE,drag_gah);
offsetFrame_gah = rotater_gah.currentFrame;
}function drag_gah(e:MouseEvent):void
{
percent_gah = (e.target.mouseX - offsetX_gah)/rotater_gah.width;var frame_gah:int = Math.round(percent_gah*rotater_gah.totalFrames) + offsetFrame_gah +1;
while (frame_gah>rotater_gah.totalFrames)
{
frame_gah -= rotater_gah.totalFrames;
}
while (frame_gah<=0)
{
frame_gah += rotater_gah.totalFrames;
}
rotater_gah.gotoAndStop(frame_gah);
rotationframe = garage_horizon_mc.currentFrame;
}I want this mouse event for every movieclip so added separately for all mcs. the problem is this being a png could be able to trigger the main_mc being static wen clicked this button.
What to do??
Or otherwise can I add the mouse event and keyboard event to the stage itself making it common for all movieclips which are image seuences???
Please help..
Thank you in advance.
-
3. Re: Problem with events and Movieclips
vari25 Sep 7, 2013 3:54 AM (in response to vari25)I have different vaiables assigned to eah mc's mouse event. So can I use The these multiple mouse events simultaneously atleast.
Is there any possiblity of that sort??
Please help..
-
4. Re: Problem with events and Movieclips
kglad Sep 7, 2013 7:33 AM (in response to vari25)i'm not sure i understand you .
i understand the code you posted. and i think i understand that you want to apply the code below Mouseevent to some other objects but those objects are png's, not movieclips. is that correct?
if so, convert the png's to movieclips (right click the png on stage>click convert to symbol>movieclip>ok).
-
5. Re: Problem with events and Movieclips
vari25 Sep 7, 2013 7:49 AM (in response to kglad)I have movieclips of images sequences(pngs).
The code posted above is what I used for mouse event for the movieclip which is made visible by the button.
This code I have for every movieclip. That is as flash does not accept same variable, so changed the variable name and used the code for every mc.
Now the main mc ie (the whole house). And other movieclips are parts of it as in garage etc. in png's.
As I told u, I have this situation where if I click on garage button, then only the mouse event for garage in functioning.
wen i want the main_mc the background also to move with the garage.
I hope I have presented clearly.
Thank u.
Any help please
-
6. Re: Problem with events and Movieclips
kglad Sep 7, 2013 8:44 AM (in response to vari25)if you want that code to apply to a group of two (or more) movieclips, reparent them and apply that code to the parent:
var p:MovieClip=new MovieClip();
addChild(p);
p.addChild(main_mc);
p.addChild(garage_horizon_mc);
var rotater_gah:MovieClip=p;
etc
////////////////////
or, if you want to apply that code to more than one movieclip concurrently, but not as a group, add that rotater_gah code to a function body and call that function sequentially.
whateverF(main_mc);
whateverF(garage_horizon_mc);
function whateverF(rotater_gah:MovieClip):void{
var offsetFrame_gah:int = rotater_gah.currentFrame;
etc
}
-
7. Re: Problem with events and Movieclips
vari25 Sep 7, 2013 11:15 AM (in response to kglad)Thank u for the reply but it has not solved my problem.
The first solution was not triggering the function.
My movieclips are in timeline in separate layers.
The second one was calling the function, but the same problem.
Yes, I want to work these in groups only.
Please help..
-
8. Re: Problem with events and Movieclips
kglad Sep 7, 2013 11:56 AM (in response to vari25)copy and paste the code you tried. there's no need to try them both. just use the one that does what you want.
-
9. Re: Problem with events and Movieclips
vari25 Sep 7, 2013 8:49 PM (in response to kglad)garage_horizon_btn.addEventListener(MouseEvent.CLICK,garage)
function garage(event:MouseEvent):void
{
images_mc.garage_horizon_mc.visible=true;
images_mc.garage_horizon_mc.stop();
images_mc.garage_moss_mc.visible=false;
images_mc.garage_ocean_mc.visible=false;
}
garage_moss_btn.addEventListener(MouseEvent.CLICK,garage1)
function garage1(event:MouseEvent):void
{
images_mc.garage_moss_mc.visible=true;
images_mc.garage_moss_mc.stop();
images_mc.garage_horizon_mc.visible=false;
images_mc.garage_ocean_mc.visible=false;
}
images_mc.main_mc.stop();
rot(images_mc.main_mc);
rot(images_mc.garage_horizon_mc);
rot(images_mc.garage_moss_mc);
function rot(rotater:MovieClip):void
{
var offsetFrame:int = rotater.currentFrame;
var offsetX:Number = 0;
var percent:Number = 0;
rotater.addEventListener(MouseEvent.MOUSE_DOWN,startDragging);
rotater.addEventListener(MouseEvent.MOUSE_UP,stopDragging);
function startDragging(e:MouseEvent):void
{
rotater.addEventListener(MouseEvent.MOUSE_MOVE,drag);
offsetX = e.target.mouseX;
}
function stopDragging(e:MouseEvent):void
{
rotater.removeEventListener(MouseEvent.MOUSE_MOVE,drag);
offsetFrame = rotater.currentFrame;
}
function drag(e:MouseEvent):void
{
percent = (e.target.mouseX - offsetX)/rotater.width;
var frame:int = Math.round(percent*rotater.totalFrames) + offsetFrame +1;
while (frame>rotater.totalFrames)
{
frame -= rotater.totalFrames;
}
while (frame<=0)
{
frame += rotater.totalFrames;
}
rotater.gotoAndStop(frame);
}
}
-
10. Re: Problem with events and Movieclips
kglad Sep 8, 2013 4:02 AM (in response to vari25)use:
var mcA:Array = [garage_horizon_mc,garage_moss_mc,garage_ocean_mc,gutter_ocean_mc,gutter_horizon_mc,gutte r_moss_mc,main_mc];
for(var i:int=0;i<mcA.length;i++){
mcA[i].addEventListener(MouseEvent.CLICK,garageF);
}
function garageF(e:MouseEvent):void{
for(var i:int=0;i<mcA.length;i++){
mcA[i].visible = false;
}
var mc:MovieClip = MovieClip(e.currentTarget);
mc.gotoAndStop(rotationframe);
mc.visible = true;
whateverF(mc);
}
function whateverF(rotater_gah:MovieClip):void{
rotater_gah.offsetFrame_gah = rotater_gah.currentFrame;
rotater_gah.offsetX_gah = 0;
rotater_gah.percent_gah = 0;
rotater_gah.addEventListener(MouseEvent.MOUSE_DOWN,startDragging_gah);
rotater_gah.addEventListener(MouseEvent.MOUSE_UP,stopDragging_gah);
}
function startDragging_gah(e:MouseEvent):void {
e.currentTarget.addEventListener(MouseEvent.MOUSE_MOVE,drag_gah);
e.currentTarget.offsetX_gah = e.target.mouseX;
}
function stopDragging_gah(e:MouseEvent):void {
e.currentTarget.removeEventListener(MouseEvent.MOUSE_MOVE,drag_gah);
e.currentTarget.offsetFrame_gah = rotater_gah.currentFrame;
}
function drag_gah(e:MouseEvent):void {
e.currentTarget.percent_gah = (e.target.mouseX - e.currentTarget.offsetX_gah)/e.currentTarget.width;
var frame_gah:int = Math.round(e.currentTarget.percent_gah*e.currentTarget.totalFrames) + e.currentTarget.offsetFrame_gah +1;
while (frame_gah>e.currentTarget.totalFrames) {
frame_gah -= e.currentTarget.totalFrames;
}
while (frame_gah<=0) {
frame_gah += e.currentTarget.totalFrames;
}
e.currentTarget.gotoAndStop(frame_gah);
}
-
11. Re: Problem with events and Movieclips
vari25 Sep 8, 2013 6:08 AM (in response to kglad)Thank u so much.
But there is an error, while compiling.
Scene 1, Layer 'actions', Frame 1, Line 131 1120: Access of undefined property rotater_gah. Line 131: e.currentTarget.offsetFrame_gah = rotater_gah.currentFrame;
What could I have done wrong??
Please help.
Thank u
-
12. Re: Problem with events and Movieclips
kglad Sep 8, 2013 6:14 AM (in response to vari25)my error. that should be:
e.currrentTarget.offsetFrame_gah = e.currentTarget.currentFrame;
-
13. Re: Problem with events and Movieclips
vari25 Sep 8, 2013 6:49 AM (in response to kglad)Thank u again.
Sorry, but again I need help because the problem exists.
now whatever I am clicking it is functioning and rotating.
The problem is,
For example; the garage_horizon_mc is a png sequence right?
now wen i am clicking the options (eg:garage_Horizon_mc), the background i.e. main_mc is hiding. actually i want the main also to be rotating with the options i enable.
is it possible?
Hope i am clear.
Thank u so much once again.
-
14. Re: Problem with events and Movieclips
kglad Sep 8, 2013 7:45 AM (in response to vari25)again, if you want to group objects so the rotate etc together, reparent them to a common parent.
or, if you want to use the current approach but not have all the movieclips (like main_mc) be clickable, remove them from mcA.
-
15. Re: Problem with events and Movieclips
vari25 Sep 8, 2013 8:08 AM (in response to kglad)Sorry, I am so confused because its way beyond my knowledge.
Could u please explain.
Reparent them .....
var p:MovieClip=new MovieClip();
addChild(p);
p.addChild(main_mc);
p.addChild(garage_horizon_mc);
Is this what u were suggesting??
Please help.
-
-
17. Re: Problem with events and Movieclips
vari25 Sep 8, 2013 7:30 PM (in response to kglad)Thank u.
But its not rotating now.
Any suggestions??
Please help.
-
18. Re: Problem with events and Movieclips
kglad Sep 8, 2013 9:04 PM (in response to vari25)again, show the complete code you're using and explain what's not rotating.
-
19. Re: Problem with events and Movieclips
vari25 Sep 9, 2013 8:35 AM (in response to kglad)Thank U so much.
I have added a target to rotate with same keyframe numbers.
It has successfully been solved.
Thank u again.
-
20. Re: Problem with events and Movieclips
kglad Sep 9, 2013 10:40 AM (in response to vari25)you're welcome.


