[Flashcoders] SWF Child - Parent Comunication

2009-04-24 Thread Dav
Hi all!

I have a problem with sending data between two SWF's.

Basically I have the parent SWF that loads in a child SWF. On the child SWF
there are several pictures that are clickable.

Now let's say the user clicks picture 2. I need the child SWF to tell the
main SWF that a picture was clicked, and also what picture it was from say
picture 1 to 10. The main SWF will then do something with that information.

So far all I have been able to find is something like this, in the child SWF
create add a dispatchEvent(new Event(jumpToImage, true)); to each
picture on click. Then in the main SWF add an event listener to the child
SWF.

Now the problem is, when I click on a picture the main SWF's listener
event.target equals the child SWF's document class ([object Child]), not the
image Movieclip instance name.

I don't really want to add a different dispatchEvent to every image:

dispatchEvent(new Event(jumpToImage1, true));
dispatchEvent(new Event(jumpToImage2, true));

dispatchEvent(new Event(jumpToImage10, true));

cause this seems wasteful, instead I would rather do this:

Child:
dispatchEvent(new Event(jumpToImage, true));

Main:
private function jumpToImage(event:Event):void
{
switch (event.target.name)
{
case picture1:
// do something with picture 1
break;
case picture2:
// do something with picture 2
break;
...
case picture10:
// do something with picture 10
break;
}
}

Any ideas?

Thanks,
Dav

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] SWF Child - Parent Comunication

2009-04-24 Thread Ashim D'Silva
when you do dispatchEvent(new Event()); the presumption is that it is
'this' that is firing it.
if you do mc1.dispatchEvent... mc2.dispatchEvent... depending on the
clip that's clicked, that should work out nicely.

Ashim

The Random Lines
My online portfolio
www.therandomlines.com



2009/4/24 Dav d...@funkdaweb.com:
 Hi all!

 I have a problem with sending data between two SWF's.

 Basically I have the parent SWF that loads in a child SWF. On the child SWF
 there are several pictures that are clickable.

 Now let's say the user clicks picture 2. I need the child SWF to tell the
 main SWF that a picture was clicked, and also what picture it was from say
 picture 1 to 10. The main SWF will then do something with that information.

 So far all I have been able to find is something like this, in the child SWF
 create add a dispatchEvent(new Event(jumpToImage, true)); to each
 picture on click. Then in the main SWF add an event listener to the child
 SWF.

 Now the problem is, when I click on a picture the main SWF's listener
 event.target equals the child SWF's document class ([object Child]), not the
 image Movieclip instance name.

 I don't really want to add a different dispatchEvent to every image:

 dispatchEvent(new Event(jumpToImage1, true));
 dispatchEvent(new Event(jumpToImage2, true));
 
 dispatchEvent(new Event(jumpToImage10, true));

 cause this seems wasteful, instead I would rather do this:

 Child:
 dispatchEvent(new Event(jumpToImage, true));

 Main:
 private function jumpToImage(event:Event):void
 {
        switch (event.target.name)
        {
                case picture1:
                        // do something with picture 1
                break;
                case picture2:
                        // do something with picture 2
                break;
                ...
                case picture10:
                        // do something with picture 10
                break;
        }
 }

 Any ideas?

 Thanks,
 Dav

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] SWF Child - Parent Comunication

2009-04-24 Thread Glen Pike

Try event.currentTarget rather than event.target

Ashim D'Silva wrote:

when you do dispatchEvent(new Event()); the presumption is that it is
'this' that is firing it.
if you do mc1.dispatchEvent... mc2.dispatchEvent... depending on the
clip that's clicked, that should work out nicely.

Ashim

The Random Lines
My online portfolio
www.therandomlines.com



2009/4/24 Dav d...@funkdaweb.com:
  

Hi all!

I have a problem with sending data between two SWF's.

Basically I have the parent SWF that loads in a child SWF. On the child SWF
there are several pictures that are clickable.

Now let's say the user clicks picture 2. I need the child SWF to tell the
main SWF that a picture was clicked, and also what picture it was from say
picture 1 to 10. The main SWF will then do something with that information.

So far all I have been able to find is something like this, in the child SWF
create add a dispatchEvent(new Event(jumpToImage, true)); to each
picture on click. Then in the main SWF add an event listener to the child
SWF.

Now the problem is, when I click on a picture the main SWF's listener
event.target equals the child SWF's document class ([object Child]), not the
image Movieclip instance name.

I don't really want to add a different dispatchEvent to every image:

dispatchEvent(new Event(jumpToImage1, true));
dispatchEvent(new Event(jumpToImage2, true));

dispatchEvent(new Event(jumpToImage10, true));

cause this seems wasteful, instead I would rather do this:

Child:
dispatchEvent(new Event(jumpToImage, true));

Main:
private function jumpToImage(event:Event):void
{
   switch (event.target.name)
   {
   case picture1:
   // do something with picture 1
   break;
   case picture2:
   // do something with picture 2
   break;
   ...
   case picture10:
   // do something with picture 10
   break;
   }
}

Any ideas?

Thanks,
Dav

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


  


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders