2009-12-19 4 views
0

file2.as에서 file1.as의 함수를 어떻게 호출 할 수 있습니까?file2.as에서 file1.as의 함수를 호출합니까?

여기 코드가 있습니다. 내가 일하는 그림자를 추가 한 다음 작동 infobubble을 추가 한 다음 작동하는 기본 SWF를 추가 한 다음이로드를 수행하는 close_button.swf을 추가하려고하고이 패키지의

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://(.yada.yada.)/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(); 
     } 
    } 
    } 
} 

swf; 그러나 리스너를 추가하려고하면 infobubble을 다시 닫을 수 없습니다.

+0

자세한 설명 : 무엇을하려고합니까? – Patrick

답변

1

협약은 일반적으로 클래스 당 하나의 .as 파일을 허용하므로 두 번째 클래스 안에 해당 클래스의 인스턴스화 된 객체에 대한 참조가 있어야합니다.

그렇다면 유용한 답변을 제공하기 위해서는 더 많은 정보가 필요합니다.

+0

ModestMaps에 대해 잘 알고 계십니까? 그렇다면 쉽게 설명 할 수 있습니다. 그렇지 않으면 코드를 포기해야합니다. 나는 as3과 flex를 처음 사용합니다. – Phil

+0

전에 사용 해본 적이 없으므로 흥미로운 것 같습니다. – Aaron

+0

위의 정보를 더 추가했습니다 – Phil

0

Tegeril의 대답에 추가하려면 : 인스턴스화 된 클래스 내부의 함수에 액세스하는 것 외에도 (유틸리티 클래스의 경우와 마찬가지로) 함수를 정적으로 만들 수 있습니다. 이 경우 메소드를 호출 할 수 있습니다 : ClassName.methodName(), 인스턴스화 할 필요없이 .... my random 2p.

+0

메신저를 통해 이것을 확장 할 수 있습니까? – Phil

+0

http://www.gskinner.com/blog/archives/2006/07/as3_singletons.html – Aaron

+0

F3 (정의로 이동) mx.controls.Alert.show(). – jeremym

관련 문제