How are you instantiating this class, Bruce? And what do you do with it
afterward? I believe that unless you add it to the stage, the object
will not dispatch the ENTER_FRAME event, so you won't see anything. The
easiest way to add it to the  stage in Flex (because FlexContainers
restrict their children to IUIComponent instances) is to create a
FlexSprite, add your component as a child of the FlexSprite, and add the
FlexSprite as a child of Application.application.

-- 
Maciek Sakrejda
Truviso, Inc.
http://www.truviso.com

-----Original Message-----
From: brucewhealton <[EMAIL PROTECTED]>
Reply-To: [email protected]
To: [email protected]
Subject: [flexcoders] Help with ActionScript class in Flex 3
Date: Thu, 17 Jul 2008 00:09:50 -0000

Hello all,
I'm not sure why this particular class is not working for me.
It's part of a tutorial. I'll include the AS below. I've been
pulling my hair out trying to figure this out. When I select debug,
it should display in the console repeatedly the text "enter frame." 
It prints what is above that but stops before calling the event
handler function called onEnterFrame. 
I don't know if I'm having a problem with the way I am setting
this up or using something in relation to the event handler. It is
part of a training on AS 3.0 with Flex, but the instructor is using
Flex 2.0 and I have Flex 3. Please help me figure this out. The file
is saved as ProgrammingBasics.as which matches the class name. 
Thanks so much in advance,
Bruce 

The code is as follows:
package {
import flash.display.MovieClip;
import com.lynda.as3et.programmingbasics.InventoryItem;
import flash.events.Event;

public class ProgrammingBasics extends MovieClip {

public function ProgrammingBasics() {
var item:InventoryItem = new InventoryItem("ActionScript 3.0
Essential Training", 1000);
trace(item.getProductName());
trace(item.getQuantity()); 
item.addItems(1000);
trace(item.getQuantity());
item.quantity = 100;
trace(item.quantity);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}

private function onEnterFrame(event:Event):void {
trace('enter frame');
}

}
}

Below this we have the Inventory.as Actionscript class. I don't think
this would be needed because it seems that everything up to
addEventListener works but here it is anyway. Please ignore what is
below if it is not necessary.

package com.lynda.as3et.programmingbasics {

public class InventoryItem {

private var _productName:String;
private var _quantity:Number;

public function get quantity():Number {
return _quantity;
}

public function set quantity(value:Number):void {
if(value < 0) {
value = 0;
}
_quantity = value;
}

public function InventoryItem(productName:String, quantity:Number) {
_productName = productName;
_quantity = quantity;
}

public function getProductName():String {
return _productName;
}

public function getQuantity():Number {
return _quantity;
}

public function addItems(quantity:Number):void {
_quantity += quantity;
}
}
}




 


Reply via email to