Skip to main content
February 7, 2010
Answered

How do I use the event.target.name String with an external dispatchEvent?

  • February 7, 2010
  • 1 reply
  • 1849 views

...I hope the title question makes sense...

On my stage I have an externally loaded SWF with a button. When clicked the button dispatches an event to the main stage.

On the main stage a listener then loads an SWF into a loader called gallery.

The gallery loader is also being shared by buttons on the main stage which use the event.target.name String to call in SWFs with corresponding names.

I am using Tweens to fade-out and -in content to the gallery when a button is pressed.

--

Loading the SWFs was working until I tried to create a universal button function for the dispatchEvent buttons...

The problem I have is that I don't know how to define the String to tell the newSWFRequest where to find the SWF when triggered by the external buttons.

(I may be doing this all wrong... but figured the best way to load an SWF on to the main stage from an external SWF was by using dispatchEvent??)

My code triggers the Event and the gallery loader fades out, but then it cannot find the new SWF:

Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.

Please can someone help me understand the way to make the String point in the right direction? (I think the only errors are in bold below)

Code:

var myTweenIn2:Tween;

var myTweenOut2:Tween;

var nextLoadS2:String;

// Listen for external event dispatched from external btns

addEventListener("contactStage", btnClickExtrnl);

function btnClickExtrnl(e:Event):void {

nextLoadS2 = ?????

myTweenOut2=new Tween(gallery,"alpha",None.easeOut,gallery.alpha,0,0.2,true);

myTweenOut2.addEventListener(TweenEvent.MOTION_FINISH,tweenOutCompleteF2);

}

// Btns Universal function

function tweenOutCompleteF2(e:TweenEvent){

myTweenOut2.removeEventListener(TweenEvent.MOTION_FINISH,tweenOutCompleteF2);

myTweenOut2=null;

    var newSWFRequest:URLRequest = new URLRequest("swfs/" + nextLoadS2 + ".swf");

myTweenIn2 = new Tween(gallery, "alpha", None.easeOut, gallery.alpha, 1, 0.2, true);

    gallery.load(newSWFRequest);

    gallery.x = Xpos;

    gallery.y = Ypos;

}

Thank you.

This topic has been closed for replies.
Correct answer kglad

When I drop in the new code to the external SWF I get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Stage@39f55ba1 to flash.display.MovieClip.

at scroller300_fla::content_2/frame11()


if that code is on the timeline of a child of your external swf's main timeline add a 3rd parent to both lines with parent.parent.

1 reply

kglad
Community Expert
Community Expert
February 7, 2010

how do you want to determine which swf should be loaded?

February 7, 2010

Hi there... by the name of the button clicked in the external SWF - ie. button 'img1' loads img1.swf

kglad
Community Expert
Community Expert
February 7, 2010

unless that listener is attached to that button, it's not going to dispatch an event.  but, if it is, you can use:

e.currentTarget.name;