How to declare the buttons in the following AS code What is the library that needs to be included
package
{
public class caml extends Sprite
{
public function buttons()
{
saveButton.visible = false;
discardButton.visible = false;
}
private function captureImage(e:MouseEvent):void
{
capture.visible = false;
saveButton.visible = true;
discardButton.visible = true;
}
}
}
If you mean buttons as in the Flash IDE and not the component one, these are SimpleButton
package {
import flash.display.SimpleButton;
public class caml extends Sprite {
public var saveButton:SimpleButton;
//...
}
}
Related
Currently I have created below class which extends ItemRenderer to add labels for all data points in Line Chart.
package lib
{
public class LineChartLabelRenderer extends UIComponent implements IDataRenderer, IFactory
{
private var _label:Label;
public var solidColor:SolidColor;
public function newInstance():*
{
return new LineChartLabelRenderer();
}
public function LineChartLabelRenderer():void
{
super();
_label = new Label();
addChild(_label);
_label.setStyle("color",0x000000);
_label.setStyle("fontSize",9);
}
private var _chartItem:ChartItem;
public function get data():Object
{
return _chartItem;
}
public function set data(value:Object):void
{
if (_chartItem == value){
return;
}
_chartItem = ChartItem(value);
if(_chartItem != null){
_label.text = LineSeriesItem(_chartItem).yValue.toString();
}
}
override protected function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
var ls:LineSeries = _chartItem.element as LineSeries;
solidColor = new SolidColor(ls.getStyle("fill"));
_label.setActualSize(_label.getExplicitOrMeasuredWidth(),20);
_label.move(unscaledWidth - _label.getExplicitOrMeasuredWidth() / 2 , this.unscaledHeight - _label.getExplicitOrMeasuredHeight() - 5);
}
}
}
It works well. However since the LineSeries may already be set with other ItemRenderer such as CircleItemRenderer or BoxItemRenderer. I found no where to let me set multiple ItemRender with one LineSeries. I want to know what the best way is to do this.
Thanks to Sunil D.
Finally I create extended ItemRenderer like below
public class LSLabelCircleItemRenderer extends CircleItemRenderer
{
private var _label:Label;
public function LSLabelCircleItemRenderer():void
{
super();
_label = new Label();
}
override protected function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
if(data != null){
var ls:LineSeries = ChartItem(data).element as LineSeries;
label.text = LineSeriesItem(data).yValue.toString();
skin.parent.addChild(label);
label.setStyle("color",ls.getStyle("fill"));
label.move(skin.x - label.getExplicitOrMeasuredWidth() / 5,skin.y - label.getExplicitOrMeasuredHeight());
}
}
}
i want to call an external function inside a class. thats the code;
in checkConnectionStatus function,
this[_funcNameForSucceededCon].apply(); doesnt work because "this" is the class, not the Application. How can i reach Application at this time or what can i do?
any help will be greatly appreciated.
best regards,
mira.
package myLibrary
{
import air.net.URLMonitor;
import flash.events.Event;
import flash.events.StatusEvent;
import flash.net.URLRequest;
public class connectionControl
{
private var _urlReq:URLRequest;
private var _urlMonitor:URLMonitor;
private var _funcNameForSucceededCon:String;
private var _funcNameForFailedCon:String;
public function connectionControl(targetURL:String, funcNameForSucceededCon:String, funcNameForFailedCon:String)
{
_urlReq = new URLRequest(targetURL);
_urlMonitor = new URLMoniotor(_urlReq);
_urlMonitor.addEventListener(StatusEvent.STATUS, checkConnectionStatus);
_funcNameForSucceededCon = funcNameForSucceededCon;
_funcNameForFailedCon = funcNameForFailedCon;
if(_urlMonitor.running == false)
{
_urlMonitor.start();
}
else
{
_urlMonitor.stop();
_urlMonitor.start();
}
}
private function checkConnectionStatus(e:Event):void
{
_urlMonitor.removeEventListener(StatusEvent.STATUS, checkConnectionStatus);
if(_urlMonitor.available)
{
this[_funcNameForSucceededCon].apply();
}
else
{
this[_funcNameForFailedCon].apply();
}
}
}
}
You have passed the name of the function to be serving as a callback. Use instead the function itself and pass it to connectionControl.
public class connectionControl
{
private var _funcSucceededCon:Function;
private var _funcFailedCon:Function;
public function connectionControl(targetURL:String, funcSucceededCon:Function, funcFailedCon:Function)
{
_urlReq = new URLRequest(targetURL);
_urlMonitor = new URLMoniotor(_urlReq);
_urlMonitor.addEventListener(StatusEvent.STATUS, checkConnectionStatus);
_funcSucceededCon= funcSucceededCon;
_funcFailedCon= funcFailedCon;
...
And:
if(_urlMonitor.available)
{
_funcSucceededCon();
}
I have a simple flex3 project with and mxml file (with some as inside of it) and FMSConnection.as
I have something like this
public class FMSConnection extends NetConnection
{
//this methods is called from the media server
public function Message(message:String):void
{
//how to display (add it to a textarea) this message, when this method is invoked ?
}
}
//in the mxml, after FMSConnection is created:
fmsConn.addEventListener(FMSConnection.MESSAGE_RECEIVED, onMessage);
private function onMessage(e:Event):void
{
fmsConn = FMSConnection(e.target);
textArea.text += fmsConn.lastMessage;
}
//FMSConnection
public class FMSConnection extends NetConnection
{
public static const MESSAGE_RECEIVED:String = "messageReceived";
public var lastMessage:String;
public function Message(message:String):void
{
lastMessage = message;
dispatchEvent(new Event(MESSAGE_RECEIVED));
}
}
Instead of declaring the lastMessage variable, you can dispatch a custom event and store the message in it if you want to.
//MsgEvent.as
public class MsgEvent extends Event
{
public static const MESSAGE_RECEIVED:String = "messageReceived";
public var message:String;
public function MsgEvent(message:String, type:String)
{
super(type);
this.message = message;
}
override public function clone():Event
{
return new MsgEvent(message, type);
}
}
//in the mxml, after FMSConnection is created:
fmsConn.addEventListener(MsgEvent.MESSAGE_RECEIVED, onMessage);
private function onMessage(e:MsgEvent):void
{
textArea.text += e.message;
}
//FMSConnection
public class FMSConnection extends NetConnection
{
public function Message(message:String):void
{
dispatchEvent(new MsgEvent(message, MsgEvent.MESSAGE_RECEIVED));
}
}
Overriding the clone method is not necessary in this case, but it's a good practice to follow while using custom events. If you don't override the clone method, you will get a runtime error while trying to redispatch the custom event from the event handler.
I know there is something I am doing wrong. In my controls I have keydown events that control my hero. As of right now, I am trying to rotate my hero but he refuses to turn . Below is my Hero Class, my control class, and gameobject class. pretty much all the classes associate with the controls class.
package com.Objects
{
import com.Objects.GameObject;
/**
* ...
* #author Anthony Gordon
*/
[Embed(source='../../../bin/Assets.swf', symbol='OuterRim')]
public class Hero extends GameObject
{
public function Hero()
{
}
}
}
Here is my Controls class. This is the class where I am trying to rotate my hero but he doesnt. The keydown event does work cause I trace it.
package com.Objects
{
import com.Objects.Hero;
import flash.events.*;
import flash.display.MovieClip;
/**
* ...
* #author Anthony Gordon
*/
public class Controls extends GameObject
{
private var aKeyPress:Array;
public var ship:Hero;
public function Controls(ship:Hero)
{
this.ship = ship;
IsDisplay = false;
aKeyPress = new Array();
engine.sr.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener);
engine.sr.addEventListener(KeyboardEvent.KEY_UP,keyUpListener);
}
private function keyDownListener(e:KeyboardEvent):void {
//trace("down e.keyCode=" + e.keyCode);
aKeyPress[e.keyCode] = true;
trace(e.keyCode);
}
private function keyUpListener(e:KeyboardEvent):void {
//trace("up e.keyCode=" + e.keyCode);
aKeyPress[e.keyCode]=false;
}
override public function UpdateObject():void
{
Update();
}
private function Update():void
{
if (aKeyPress[37])//Key press left
ship.rotation += 3,trace(ship.rotation ); ///DOESNT ROtate
}//End Controls
}
}
Here is GameObject Class
package com.Objects
{
import com.Objects.Engine;
import com.Objects.IGameObject;
import flash.display.MovieClip;
/**
* ...
* #author Anthony Gordon
*/
public class GameObject extends MovieClip implements IGameObject
{
private var isdisplay:Boolean = true;
private var garbage:Boolean;
public static var engine:Engine;
public var layer:Number = 0;
public function GameObject()
{
}
public function UpdateObject():void
{
}
public function GarbageCollection():void
{
}
public function set Garbage(garb:Boolean):void
{
garbage = garb;
}
public function get Garbage():Boolean
{
return garbage
}
public function get IsDisplay():Boolean
{
return isdisplay;
}
public function set IsDisplay(display:Boolean):void
{
isdisplay = display;
}
public function set Layer(l:Number):void
{
layer = l;
}
public function get Layer():Number
{
return layer
}
}
}
Looks like your keyUpListener and keyDownListener methods aren't calling the UpdateObject function.
Try listening for your KeyboardEvent on stage instead of engine.sr (not sure what that is)
If you put them on anything other than the stage you will need to click that specific thing first to give it focus for the events to work.
Also, the line:
ship.rotation += 3,trace(ship.rotation );
in your Control class looks a bit broken.
I've trouble getting my components to update when the params has changed:
package mycompany
{
import flash.events.Event;
import mx.events.SliderEvent;
import mx.controls.HSlider;
import mx.controls.sliderClasses.Slider;
public class FromToSlider extends HSlider
{
/* from: */
private var _from:int;
[Bindable]
public function get from():int
{
return _from;
}
public function set from(value:int):void
{
this._from = value;
this.values[0] = value;
invalidateProperties();
}
/* //from */
/* to: */
private var _to:int;
[Bindable]
public function get to():int
{
return _to;
}
public function set to(value:int):void
{
this._to = value;
this.values[1] = value;
}
/* //to */
override public function initialize():void
{
super.initialize();
addEventListener(SliderEvent.CHANGE, handleChange, false, 0, true);
}
protected function handleChange(event:SliderEvent):void
{
var ct:Slider=Slider(event.currentTarget);
this.from = ct.values[0];
this.to = ct.values[1];
}
}
}
When I set "from" and "to" the thumbs aren't updating. I've tried invalidateProperties but that didn't work.
Add a call to invalidateDisplayList() after invalidateProperties(). That will ensure that Flex redraws the component on the next keyframe.
You should also add the same to the 'set to()' function.