Hi there! I’m pretty new to AS3 and have a problem.
I’m trying to build a WOTD (where the WOTD gets translated into German) widget and an extra add-on that is a input text translator. The WOTD part works fine but my translator isn’t. I’m using a google translation api btw.
At the moment when clicking on my translate button I get Error Code #1009:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at be.boulevart.google.ajaxapi.translation::GoogleTranslation/onResponse()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
here’s my code and I’d really appreciate any help!
package{
import flash.display.*;
import flash.events.*;
import gs.*;
import fl.motion.easing.*;
import framework.utils.LoadXML;
import be.boulevart.google.ajaxapi.translation.*;
import be.boulevart.google.ajaxapi.*;
import be.boulevart.google.ajaxapi.search.*
import be.boulevart.google.apicore.GoogleApiKeyStore;
import be.boulevart.google.events.*;
public dynamic class wotd_widget extends MovieClip{
//vars
var loadXML:LoadXML = new LoadXML('http://wordsmith.org/awad/rss1.xml',onComplete);
private var mc01:MovieClip;
private var mclayout:MovieClip;
//constructor
public function wotd_widget():void{
trace('wotd');
init();
init_btn();
}
private function onComplete($xml:XML):void{
//trace($xml);
trace($xml.channel.item[0].title);
trace($xml.channel.item[0].description);
wotd_In.text = $xml.channel.item[0].title;
des_In.text = $xml.channel.item[0].description;
var gt:GoogleTranslation = new GoogleTranslation();
gt.translate($xml.channel.item[0].title,'en','de');
gt.addEventListener(GoogleApiEvent.TRANSLATION_RESULT,onTranslate);
}
private function onTranslate(e:GoogleApiEvent):void{
//trace(e.data.to);
//trace(e.data.orig);
//trace(e.data.from);
//trace(e.data.result);
trans_In.text = e.data.result;
}
private function init_btn():void{
this.mc01 = new trans_btn();
this.mc01.x = 340.9;
this.mc01.y = 234.4;
addChild(this.mc01);
TweenMax.to(this.mc01,1,{x:340.9, y:234.4, ease:Cubic.easeOut,onComplete:onComplete1});
}
private function onComplete1():void{
this.mc01.buttonMode = true;
this.mc01.addEventListener(MouseEvent.ROLL_OVER,mEvent01);
this.mc01.addEventListener(MouseEvent.ROLL_OUT,mEvent01);
this.mc01.addEventListener(MouseEvent.CLICK,mEvent01);
}
function mEvent01(e:MouseEvent):void{
switch(e.type){
case 'rollOver':
//this executes when you rollover the target
TweenMax.to(MovieClip(e.target),0,{tint:0xFF75B6});
break;
case 'rollOut':
//this executes when you rolloff the target
TweenMax.to(MovieClip(e.target),0,{removeTint:true});
break;
case 'click':
//this executes when you click the target
onClick01();
break;
}
function onClick01():void{
var gt2:GoogleTranslation = new GoogleTranslation();
gt2.translate(input_trans.text,'en','de');
gt2.addEventListener(GoogleApiEvent.TRANSLATION_RESULT,onTranslate2);
}
function onTranslate2(e:GoogleApiEvent):void{
trace(e.data.to);
trace(e.data.orig);
trace(e.data.from);
trace(e.data.result);
output_trans.text = e.data.result;
}
}