PDA

Volledige versie bekijken : via asfunction een function binnen een class aanroepen


jawel
%Europe/Berlin %456 %2007, 11:56
Hoi,

ik wil via asfunction een functie binnen een class aanroepen. Nu heb ik begrepen dat dat via allerlei moeilijke constructies (http://www.flashfocus.nl/forum/showthread.php?t=8800) mogelijk is, maar daar snap ik niet zo veel van, ik vroeg me af of dit makkelijker kon? Maakt het wat uit of een functie private of public is? Is er een manier om via een stirng een functie aan te vragen?

bedankt voor de tijd

Dauntless
%Europe/Berlin %479 %2007, 12:30
In MediaMonkey's class zit eigenlijk veel dat niet echt met het as-function gebeuren te maken heeft. Hier is versimpelde versie:
import mx.utils.Delegate;
class Application
{
private var root:MovieClip;
private var textField:TextField;

public function Application(p_root:MovieClip)
{
this.root = p_root;
createTextField();
}

private function createTextField():Void
{
this.textField = this.root.createTextField("myTextField", 1, 0, 0, 200, 20);
this.textField.html = true;
this.textField.htmlText = "<a href='asfunction:callFunction,hello world|how are you today?'>click me</a>";
this.textField._parent.callFunction = Delegate.create(this, asFunctionHandler);
}

private function asFunctionHandler(p_args:String):Void
{
trace(p_args.split("|"));
}


}

pimmeelhuysen
%Europe/Berlin %481 %2007, 12:33
Hey,

ik heb hier pas ook mee lopen klooien, maar zo moeilijk is het niet.
Gebruik deze regel in je XML:

<a href="asfunction:getSongNum,0">gewoon jouw tekst die je wilt tonen</a>

Hierin is "getSongNum" de functie die je moet beschrijven in je AS.

_global.getSongNum = function(){
trace("Het is gelukt")
}

Dauntless
%Europe/Berlin %483 %2007, 12:36
@Pimm: Gebruikt hij dan xml ? En dit is een scoping probleem in classes, iets wat niet zo simpel op te lossen is. De topic starter weet wel hoe hij het moet gebruiken, maar de functie wordt niet getriggered omdat de scoping in classes vaak vrij moeilijk ligt.

jawel
%Europe/Berlin %498 %2007, 12:58
Bedankt allebei voor de tijd
public function loadMsg(msg,onclose) {
var blinder:MovieClip = _root.createEmptyMovieClip("blinder",_root.getNextHighestDepth());
blinder.beginFill(0x000000,75);
blinder.moveTo(0,0);
blinder.lineTo(Stage.width,0);
blinder.lineTo(Stage.width,Stage.height);
blinder.lineTo(0,Stage.height);
blinder.lineTo(0,0);
blinder.endFill();
blinder.useHandCursor = false;
blinder.onRollOver = function () {
}
var box:MovieClip = _root.createEmptyMovieClip("box",_root.getNextHighestDepth());
var bd:MovieClip = box.createEmptyMovieClip("bd",box.getNextHighestDepth());
bd.beginFill(0x00AAFF,100);
bd.moveTo(0,0);
bd.lineTo(10,0);
bd.lineTo(10,10);
bd.lineTo(0,10);
bd.lineTo(0,0);
bd.endFill();

var msgtxt:TextField = box.createTextField("msgtxt",box.getNextHighestDepth(),0,0,300,0);
msgtxt.html = true;
msgtxt.embedFonts = true;
msgtxt.selectable = true;
msgtxt.multiline = true;
msgtxt.wordWrap = true;

var css:TextField.StyleSheet = new TextField.StyleSheet();
css.load(_global.loc+"php/style.php?color1=0x000000&color2=0xFF00CC");
css.onLoad = function(success) {
if(success) {
msgtxt.styleSheet = css;
msgtxt.htmlText = "<p>"+msg;
msgtxt.htmlText += "<br/><br/><a href=\"asfunction:"+onclose+"\">Klik hier om dit venster te sluiten</a></p>";
msgtxt.autoSize = "left";
bd._width = msgtxt._width + 20;
bd._height = msgtxt._height + 20;
msgtxt._x = 10;
msgtxt._y = 10;
box._x = (Stage.width/2)-(box._width / 2);
box._y = (Stage.height/2)-(box._height / 2);
}
}
}

Dit is overigens een functie om berichtjes weer te geven. Ik wil via php een functie binnen m'n class aanroepen (handler). Ik zal even kijken hoe dat met die Application class werkt, nogmaals bedankt

jawel
%Europe/Berlin %510 %2007, 13:15
ik heb het nu zo:

private function asFunctionHandler(p_args:String):Void {
_global.tt(p_args.split("|"));
}

en

(...)
msgtxt._parent.callFunction = Delegate.create(this, asFunctionHandler);
(...)
msgtxt.htmlText += "<br/><br/><a href='asfunction:callFunction,"+onclose+"'>Klik hier om dit venster te sluiten</a></p>";

en ik krijg inderdaad een trace met onclose, maar hoe moet ik nu de functie aanroepen die onclose aangeeft? Ik snap ook niet precies wat de Application function doet, ben niet zo goed in dit soort dingen.

Thanks

jawel
%Europe/Berlin %543 %2007, 14:02
Heb 'm:

msgtxt._parent.callFunction = Delegate.create(this, this[onclose]);

Bedankt allebei, en ook MediaMonkey denk! hallee

Dauntless
%Europe/Berlin %600 %2007, 15:24
Die Application function was niets meer dan de constructor van de Application class.