View Full Version : addEventListener to loader? or loaded swf?
Snickers
12-19-2009, 07:03 PM
I am loading an external swf file using the following code:
//add close button
var reqButton:URLRequest = new URLRequest(btn_close);
var loader2:Loader = new Loader();
loader2.load(reqButton);
addChild(loader2);
loader2.addEventListener(MouseEvent.CLICK, closeInfoBubble);
function closeInfoBubble(event:MouseEvent):void
{
infoClip.removeMarkerObject(infoBubble)
infoBubble = null
}
Question 1:
Once the loader loads my image, and I click on it, nothing is happening. Am I supposed to be adding the EventListener to the loader or something else?
Question 2:
How can I detect the height and width of the swf file in the loader?
wvxvw
12-19-2009, 07:17 PM
loader.loaderInfo.width;
If you know that the content is an image and you can draw it into BitmapData - that's the best way to go - draw it into BitmapData and the Sprite.graphics.beginBitmapFill().
Snickers
12-19-2009, 08:03 PM
With my image being an externally loaded swf, how do I go about following your advice? I'm not sure of how to code it up.
wvxvw
12-19-2009, 08:54 PM
mmm... well, SWF isn't an image, images are JPEG / GIF / BMP etc... if you load a SWF, then it becomes part with your other code - so, everything that applies to your other code applies to the loaded SWF as well. There are however limitations if loaded SWF is AVM1Movie.
From having another look at your code... is it a FLA timeline code? If so, why posting it in Flex forum? And, if it's not - why closeInfoBubble has no accessor? Or, if this code is inside another function - then just don't use anonymous functions.
Snickers
12-19-2009, 10:19 PM
I'm using Flex with as3, however, the images i am loading are external swf files. I need them to be external swf files so that I can change the external swf files without having to change my entire flex program.
I dont know what an "accessor" is. something is wrong with my code and I can't figure it out.
I am still testing this closebutton feature because I desperately need it to work by monday... :confused:
package com.modestmaps
{
import com.modestmaps.overlays.MarkerClip;
import flash.display.Graphics;
import flash.display.Loader;
import flash.display.Shape;
import flash.display.Sprite;
import flash.filters.BlurFilter;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.net.URLRequest;
import flash.text.TextField;
//import mx.core.Application;
import mx.core.Application;
import flash.events.MouseEvent;
public class InfoBubble extends Sprite
{
private var btn_close:String = "http://www.cvcmaps.com/SabineParish/media/close_button.swf";
public var textField:TextField;
public var background:Shape;
public var shadow:Shape;
public var infoClip:MarkerClip;
protected var map:InfoMap;
//var infoClip:MarkerClip;
public var infoBubble:InfoBubble;
public function InfoBubble(urlLink:String)
{
//the name of my markers are set to the links of the swf files in which I want to load into the infobubble
this.name = urlLink;
this.mouseEnabled = false;
this.mouseChildren = true;
this.buttonMode=false;
shadow = new Shape();
shadow.filters = [ new BlurFilter(16, 16) ];
shadow.transform.matrix = new Matrix(1, 0, -0.5, 0.5, 0, 0);
addChild(shadow);
background = new Shape();
addChild(background);
textField = new TextField();
textField.selectable = false;
//the infobubble is still sized according to the textField.width and height
//I don't know how to get the size of the loaded swf
textField.width = textField.textWidth+432+4;
textField.height = textField.textHeight+288+4;
//add main swf
var request:URLRequest = new URLRequest(urlLink);
var loader:Loader = new Loader();
loader.load(request);
addChild(loader);
//position the main swf
//current measurements of swf file w432 h288
loader.y = -288 - 37;
loader.x = mx.core.FlexGlobals.topLevelApplication.LBloaderX;
//add close button
var reqButton:URLRequest = new URLRequest(btn_close);
var loader2:Loader = new Loader();
loader2.load(reqButton);
addChild(loader2);
loader2.addEventListener(MouseEvent.CLICK, closeInfoBubble);
function closeInfoBubble(event:MouseEvent):void
{
infoClip.removeMarkerObject(infoBubble)
infoBubble = null
}
//position the closebutton swf
//current measurements of closebutton swf file w18 h18
loader2.y = -286 - 37;
loader2.x = mx.core.FlexGlobals.topLevelApplication.LBloader2X ;
// remember that things in marker clips are positioned with (0,0) at the given location
textField.y = -textField.height - 35;
textField.x = -10;
//I need to find out how to detect the width and height of the swf file loaded into loader2
//instead of the size of the textField
var rect:Rectangle = textField.getRect(this);
// get your graph paper ready, here's a "speech bubble"
background.graphics.beginFill(0x12345);
shadow.graphics.beginFill(0x000000);
for each (var g:Graphics in [ background.graphics, shadow.graphics ] ) {
g.moveTo(rect.left, rect.top);
g.lineTo(rect.right, rect.top);
g.lineTo(rect.right, rect.bottom);
g.lineTo(rect.left+15, rect.bottom);
g.lineTo(rect.left+10, rect.bottom+15);
g.lineTo(rect.left+5, rect.bottom);
g.lineTo(rect.left, rect.bottom);
g.lineTo(rect.left, rect.top);
g.endFill();
}
}
}
}
wvxvw
12-19-2009, 11:22 PM
Accessor (or access modifier) is public, private, internal, protected or any custom namespace you put your method or property.
So, to make it more clear: in your case function closeInfoBubble should be made a class method, not an inline (anonymous / nested function). This sort of functions don't work good in AS3 - therefor don't use them.
And, again, SWF files are not images - not by any standard, animations at worst.
Another thing that may happen in your code which you may not expect is that Loader#load() is asynchronous, that is loading will finish after the InfoBubble function exits - so there is no way to know what the size of the loaded content is because at that time the content isn't loaded yet. You may only know the size at the time or after Loader#contentLoaderInfo will dispatch Event.COMPLETE event.
Snickers
12-19-2009, 11:56 PM
Thank you wvxvw for your help. I have been struggling with this for days.
Are you saying I should create a whole new closeInfoBubble.as file for that function? How do I then call that closeInfoBubble.as?
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.