• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Make an item glow when the player is walking

Contributor ,
Nov 07, 2013 Nov 07, 2013

Copy link to clipboard

Copied

Hi,

I'm making a game (point & click) and I'm trying to make the usable item glow when the player is walking.

It’s quite simple but I don’t why I fail..I must miss something.

I have already the code as my usable item is glowing when I'm putting it on an other usable item...

So I've got a Engine class (where I'm trying to put the code that make the item glow when the player is walking.

And a DraggedItem Class (This class allows the user to drag inventory items over the stage).

In my DraggedItem class I've got this function :

private function itemGlow(isGlowing:Boolean):void{

                              if (isGlowing){

                                        var glow:GlowFilter = new GlowFilter();

                                        glow.color = 0xFFFF00;

                                        glow.alpha = .75;

                                        glow.blurX = 10;

                                        glow.blurY = 10;

                                        glow.quality = BitmapFilterQuality.MEDIUM;

                                        draggedItem.filters = [glow];

                              } else {

                                        draggedItem.filters = null;

                              }

                    }

So, in my Engine class I'd like to use this function when my player is walking.

I tought I could put something like this :

back = new Background(stage, thisBack);

back.currentBack.ground.addEventListener(MouseEvent.MOUSE_DOWN, shineItems, false, 0, true);

private function shineItems(e:MouseEvent):void{

                                        trace(shineItems);

                              var thisClip = usableItems

                              if (playerControl){

                                        stage.dispatchEvent(new Event("playerMoving"));

draggedItem.itemGlow;

                                        }

                              }

But it's not it.

I've must import the function in the wrong way...

So I've try to add in the Engine Class (and change "draggedItem.itemGlow;" by "itemGlow;")

private function itemGlow(isGlowing:Boolean):void{

                              if (isGlowing){

                                        var glow:GlowFilter = new GlowFilter();

                                        var thisClip = usableItems

                                        glow.color = 0xFFFF00;

                                        glow.alpha = .75;

                                        glow.blurX = 10;

                                        glow.blurY = 10;

                                        glow.quality = BitmapFilterQuality.MEDIUM;

                                        thisClip.filters = [glow];

                              } else {

                                        thisClip.filters = null;

                              }

                    }

But it's not working either....

Any idea ?

TOPICS
ActionScript

Views

927

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 07, 2013 Nov 07, 2013

Copy link to clipboard

Copied

I've changed "draggedItem.itemGlow"  by "draggedItem.itemGlow(true);".

And marked the function itemGlow (in the draggedItem class) as PUBLIC.

But now I've got this error :

TypeError: Error #1009: Cannot access a property or method of a null object reference. at com.laserdragonuniversity.alpaca::Engine/shineItems()

It seems that draggedItem.itemGlow(true); is the problem..


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 07, 2013 Nov 07, 2013

Copy link to clipboard

Copied

it probably has sth. to do with how you adrees an instance of your dragged item class.

if you instantiate your DraggedItem class

with

var draggedItem:DraggedItem = new DraggedItem();

and IsGlowing is a property of this MovieClip

the public fucntion inside the DraggedItem.as should be written like this:

                              if (isGlowing){
                                        var glow:GlowFilter = new GlowFilter();
                                        glow.color = 0xFFFF00;
                                        glow.alpha = .75;
                                        glow.blurX = 10;
                                        glow.blurY = 10;
                                        glow.quality = BitmapFilterQuality.MEDIUM;


                                        this.filters = [glow];
                              } else {
                                        this.filters = [];
                              }

in this case the keyWord "this" refers to any instance of the class you are creating,

while "draggedItem" (your soultion) would refer to a MovieClip called "draggedItem" inside your "draggedItem" instance, which is probably not what you intended.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 07, 2013 Nov 07, 2013

Copy link to clipboard

Copied

It doesn't work. new DraggedItem(); needs 2 arguments.

Is it simpler to rewrite a new function only for glowing the usable item ?

Like that :

if I write a new function directly in the Engine Class.

private function shineItems(e:MouseEvent):void{

trace(shineItems);

var thisClip = usableItems

if (playerControl){

stage.dispatchEvent(new Event("playerMoving"));

itemShine(true);

}

public function itemShine(isShining:Boolean):void{

if (isShining){

var glow:GlowFilter = new GlowFilter();

glow.color = 0xFFFF00;

glow.alpha = .75;

glow.blurX = 10;

glow.blurY = 10;

glow.quality = BitmapFilterQuality.MEDIUM;

usableItems.filters = [glow];

} else {

usableItems.filters = null;

}

}

doesn't seem to work. but I'll look into it (no errors, but nothing is happening..). But the trace tells me that the function is geting called

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 07, 2013 Nov 07, 2013

Copy link to clipboard

Copied

LATEST

Is it simpler to rewrite a new function only for glowing the usable item ?

It doesn`t make much sense to use multiple classes, if you end up cross referencing them.

The Engine shouldn`t care about how your draaggableItem reacts to user input.

new DraggedItem(); needs 2 arguments.

show the contructor of your DraggableItem class

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines