Jemes
Jemes

Reputation: 407

Dynamic Object Tween

I'm new to Flash/ActionScript 3, I'm trying to dynamically update the Object in a Tween.

The info variable will change depending on what button is pressed.

I'm currently getting the error below...

TypeError: Error #1009: Cannot access a property or method of a null object reference. at fl.transitions::Tween/setPosition() at fl.transitions::Tween/set position() at fl.transitions::Tween() at Map_fla::MainTimeline/frame1()

I'm not sure where I'm going wrong?

import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;

var info:MovieClip;

var myTween:Tween = new Tween(info, "alpha", Strong.easeOut, 1, 0, 2, true);
myTween.stop();

btn_Button.addEventListener(MouseEvent.CLICK, onClick);

btn_Button.addEventListener(MouseEvent.CLICK, onClick2);

function onClick(e:MouseEvent){
    info = mc_England;
    myTween.start();
}

function onClick2(e:MouseEvent){
    info = mc_Scotland;
    myTween.start();
}

Upvotes: 0

Views: 831

Answers (1)

grapefrukt
grapefrukt

Reputation: 27045

info is null when you're creating the tween, that's why you're getting a null reference error. Move the instantiation of the tween into your click handlers and you'll be fine.

function onClick(e:MouseEvent){
    applyTween(mc_England);
}

function onClick2(e:MouseEvent){
    applyTween(mc_Scotland);
}

function applyTween(target:MovieClip){
    var myTween:Tween = new Tween(target, "alpha", Strong.easeOut, 1, 0, 2, true);
    myTween.start();
}

Upvotes: 1

Related Questions