This is the code that i compiled using mxmlc the free flex sdk. It compiled and i ran it. Helloworld not displayed
package
{
import org.flixel.*;
public class PlayState extends FlxState
{
override public function create():void
{
add(new FlxText(0,0,100,"Hello, World!")); //adds a 100x20 text field at position 0,0 (upper left)
}
}
}
Expected output is = HelloWorld. But is not displayed
You'll need to provide an FlxGame subclass too. It may be easiest for you to take an existing Flixel project that works out of the box such as AdamAtomic's HelloWorld and modify it to suit your needs.
Try this instead:
package
{
import org.flixel.*;
public class HelloWorld extends FlxState
{
private var title_text:FlxText;
public function HelloWorld() { }
override public function create():void
{
title_text = new FlxText(20, 0, 300, 'Lunarium');
title_text.setFormat(null, 50, 0xffffffff, "center");
add(title_text);
}
override public function update():void
{
if(FlxG.keys.X)
{
FlxG.fade(0xff131c1b, 1, onFade);
}
super.update();
}
protected function onFade():void
{
//FlxG.switchState(new SmallPlay2());
}
}
}
There are plenty of tool tips to help you figure out what the different settings mean. I found flixel rather easy to use coming from a Multimedia Fusion 2 background.
Enjoy!
Related
I have a few different views & screens which all use a few variants of Group, VGroup or HGroup and to have them laid out correctly, I find myself having to write and rewrite again with either
gap="0"
or with TileLayout
horizontalGap="0" verticalGap="0"
to get them all to layout correctly, and how I want. Currently the only option I see of being able to set them to zero globally is to set up a heavy global listener, ie.
protected function globalListener():void
{
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, true);
}
protected function onAddedToStage(event:Event):void
{
var g:Group = event.target as Group;
if(g)
{
if( g.layout.hasOwnProperty('gap') )
{
g.layout['gap'] = 0;
}
else
{
var l:TileLayout = g.layout as TileLayout;
if(l)
{
l.verticalGap = l.horizontalGap = 0;
}
}
}
}
or creating a new package with these layouts, and adding gap=0 to them,
package overrides.gapless
{
import spark.components.HGroup;
public class HGroup extends spark.components.HGroup
{
public function HGroup()
{
gap = 0;
}
}
}
and
package overrides.gapless
{
import spark.layouts.TileLayout;
public class TileLayout extends spark.layouts.TileLayout
{
public function TileLayout()
{
horizontalGap = 0;
verticalGap = 0;
}
}
}
and the like. I've checked the source code of the relevant files (mainly VerticalLayout, HorizontalLayout and TileLayout) and can see the values hardcoded in, but still can't fully believe there's no other way to do it.
I've only recently started delving into Flex, and am loving it's skinning options, but am a bit mystified about this one.
Thanks for any and all help as to how to do this.
im a newbie in flex. Im have a question :)
I have
[Bindable]
private var model:AlgorithmModel = new AlgorithmModel();
private var serviceProxy:Algorithm = new Algorithm( model );
In MXML
private function Show():void
{
// now model.Solve_SendResult = null
while(i<model.Solve_SendResult.length) //
{
Draw(); //draw cube
}
}
private function Solve_Click():void
{
//request is a array
Request[0] = 2;
Request[1] = 2;
Request[2] = 3;
serviceProxy.Solve_Send(request);
Show();
}
<s:Button x="386" y="477" label="Solve" click="Solve_Click();"/>
And when i call serviceProxy.Solve_Send(request); with request is array and i want use model.Solve_SendResult in my code flex to draw many cubes use papervison3d but in the first time i received model.Solve_SendResult = null . But when I click again then everything OK.
Anyone help me? Thanks?
The model.Solve_SendResult object contains a result of the executed serviceProxy.Solve_Send(request) method. The Solve_Send will be executed asynchronously and as a result, at the moment when you fire the show method the Solve_SendResult object may be still null.
As a solution, you can use the following:
Create a custom event
package foo
{
import flash.events.Event;
public class DrawEvent extends Event
{
public static const DATA_CHANGED:String = "dataChanged";
public function DrawEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
}
}
}
In your Algorithm class define the following:
[Event(name=DrawEvent.DATA_CHANGED, type="foo.DrawEvent")]
public class Algorithm extends EventDispatcher{
//your code
In the Solve_SendHandler method of the Algorithm class add the following
public virtual function Solve_SendHandler(event:ResultEvent):void
{
dispatchEvent(new DrawEvent(DrawEvent.DATA_CHANGED));
//your code
}
In your MXML class create onLoad method and add an event listener to an instance of the Algorithm class as it shown below:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="onLoad()">
public function onLoad():void
{
serviceProxy.addEventListener(DrawEvent.DATA_CHANGED, onDataChanged);
}
private function onDataChanged(event:DrawEvent):void{
while(i<model.Solve_SendResult.length) //
{
Draw(); //draw cube
}
}
make the following changes in the Solve_Click() method:
private function Solve_Click():void
{
//request is a array
Request[0] = 2;
Request[1] = 2;
Request[2] = 3;
serviceProxy.Solve_Send(request);
}
That is it! So, basically the code above do the following: you added a listener to your service (algorithm class), and the listener is listening for the DrawEvent.DATA_CHANGED event. The DrawEvent.DATA_CHANGED will be dispatched when your client receive a result of the Solve_Send invocation. Thus, the onDataChanged will draw your cube or do whatever you want :)
The approach above is basic and you have to know how events work in flex and how you can deal with it. Additional information is available here:
http://livedocs.adobe.com/flex/3/html/help.html?content=createevents_3.html
http://livedocs.adobe.com/flex/3/html/help.html?content=events_07.html
Regards,
Cyril
I'm trying to set the height of a vertical bar (activityBar) but it does not appear to do anything. i have tried something similar with the whole component, but setting the dimensions does nothing (even in the mxml used to instantiate the class). Indeed, I've added transparent graphics just to give the component some dimensions
I'm not sure what I'm doing wrong. It's something bad though; my approach seems dire.
FYI: I'm trying to create a mic activity bar that will respond to the mic by simply setting the height of the activityBar child (which seems to me to be more efficient than redrawing the graphics each time).
Thanks for your help!
package components {
import mx.core.UIComponent;
public class MicActivityBar extends UIComponent {
public var activityBar:UIComponent;
// Constructor
public function MicActivityBar() {
super();
this.opaqueBackground = 0xcc4444;
graphics.beginFill(0xcccccc, 0);
graphics.drawRect(0,-15,5,30);
graphics.endFill();// background for bar
activityBar = new UIComponent();
activityBar.graphics.beginFill(0xcccccc, 0.8);
activityBar.graphics.drawRect(0,-15,5,20);
activityBar.graphics.endFill();
activityBar.height=10;
addChild(activityBar);
}
}
}
package components {
import mx.core.UIComponent;
public class MicActivityBar extends UIComponent {
public var activityBar:UIComponent;
private var _w:Number;
// Constructor
public function MicActivityBar() {
super();
this.opaqueBackground = 0xcc4444;
graphics.beginFill(0xcccccc, 0);
graphics.drawRect(0,-15,5,30);
graphics.endFill();// background for bar
activityBar = new UIComponent();
activityBar.graphics.beginFill(0xcccccc, 0.8);
activityBar.graphics.drawRect(0,-15,5,20);
activityBar.graphics.endFill();
activityBar.height=10;
addChild(activityBar);
}
public function get w():Number {
return _w;
}
public function set w(value:Number):void {
_w = value;
}
override protected function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);
this.height=w;
this.weight=w;
}
}
}
See my updated code above.
I have a custom class that embeds a movie clip. When I try to use parent class's such as gotoAndStop(). It ignores the method. I would like to know what I am doing wrong. below is my code. I call the method in my constructor Thanks!
game object class
package com.objects
{
import com.eapi.IGameObject;
import flash.display.MovieClip;
/**
* ...
* #author Anthony Gordon
*/
public class GameObject extends MovieClip implements IGameObject
{
public function GameObject()
{
}
}
}
hero class. gotoAndStop() in the constructor
package com.objects
{
import flash.display.MovieClip;
import flash.events.*;
/**
* ...
* #author Anthony Gordon
*/
[Embed(source='../../../bin/Assets.swf', symbol='Hero')]
public class Hero extends GameObject
{
private var aKeyPress:Array;
private var jumpDisabled:Boolean = false;
public function Hero()
{
gotoAndStop(1) ///<----------------Doesnt stop. Just keeps playing
wY = 150;
wX = 90;
speed = .5;
aKeyPress = new Array();
TheGame.sr.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener);
TheGame.sr.addEventListener(KeyboardEvent.KEY_UP,keyUpListener);
}
private function keyDownListener(e:KeyboardEvent):void {
//trace("down e.keyCode=" + e.keyCode);
aKeyPress[e.keyCode]=true;
}
private function keyUpListener(e:KeyboardEvent):void {
//trace("up e.keyCode=" + e.keyCode);
aKeyPress[e.keyCode]=false;
}
override public function UpdateObject():void
{
Controls();
updatePosition();
}
private function Controls():void
{
if (aKeyPress[38])//Key press up
;//dy -= speed;
else if (aKeyPress[40])//Key press down
dy += speed;
if (aKeyPress[37])//left
{
dx -= speed;
}
else if (aKeyPress[39])//Right
{
dx += speed;
}
if (aKeyPress[32]){//space
jump();
}
}//End Controls
private function jump():void
{
if (!jumpDisabled)
{
if (onGround)
{
gotoAndStop(10);
dy = -15;
jumpDisabled = true;
}
}
else
{
jumpDisabled = false;
}
}
}
}
The problem is that when you embed a swf of a movie clip actually what you got is a movieclip with and added child Loader who get inside the real movieclip.
You must try something like
var aMovie:MovieClip;
Loader(this.getChildAt(0)).getLoaderInfo.addListener(Event.Complete, methodEventCompleteName);
function methodEventCompleteName(e:Event)
{
aMovie = MovieClip(Loader(this.getChildAt(0)).content);
}
I really suggest to try learn to use SWC files. I export him on flash cs5 IDE then add on a lib folder into my proyect, then in flashdeveloper ide right click into the SWC file and check the "add to library" option. Inside a class can directly instantiate the movieClip name into the SWC file like this:
var aMovie:MovieClip = new MyMovieClipFromSWC() as MovieClip;
and it's done :D
Hope this help to someone... because I spend like 3 weeks trying to figured out and finally get it... there isn't enough info about it...
You should add a listener to know when its added to stage and initialize your clip there.
public function Hero() {
if ( stage ) _init( );
else addEventListener(Event.ADDED_TO_STAGE, _init );
}
private function _init( e:Event = null ):void {
removeEventListener( Event.ADDED_TO_STAGE, _init );
gotoAndStop(1) ///<----------------Doesnt stop. Just keeps playing
wY = 150;
wX = 90;
speed = .5;
aKeyPress = new Array();
TheGame.sr.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener);
TheGame.sr.addEventListener(KeyboardEvent.KEY_UP,keyUpListener);
}
Also, i think this reading Order of operations by senocular would be rather interesting.
It explains frame execution in timeline objects and object creation.
Figure it out. I forgot that my MovieClip was encapuslated in another movieclip. So i had to call the movieclip that was inside of the Hero symbol
I noticed you're still using
[Embed(source='../../../bin/Assets.swf', symbol='Hero')]
Since you're using flash develop (but same goes for flex) there's no reason you can't use SWCs
Although I can't tell with 100% certainty that that is what is causing this issue, once you start using SWCs it will make a world of difference.
Not only will you no longer need to use the embed code, things like gotoandplay and extending classes will work better, and you will be able to see the classes and objects within.
SWFs are not meant to be used this way, and sooner you stop using them for things they are not meant for, the the easier it will be.
When I debug my code nothing appears on screen. I've rechecked the code and consulted with others yet nothing appears. My html template is fine.
package {
import flash.display.Sprite;
import flash.events.*;
public class asgnv2 extends Sprite
{
var lineY = 0;
public function asgnv2()
{
stage.addEventListener(Event.ENTER_FRAME, update);
graphics.lineStyle(1);
}
function update(e){
graphics.clear();
graphics.moveTo(0 ,lineY);
graphics.lineTo(100, lineY);
lineY+=0.5;
}
}
}
unless asgnv2 is Document class, it is not going to work, as you are registering ENTER_FRAME event on the stage inside the constructor of asgnv2. A DisplayObject can not access stage property until it is added to Stage Display List. So try the following. public function asgnv2(){
this.addEventListener(Event.ADDED_TO_STAGE, onAdded);
graphics.lineStyle(1);
}
private function onAdded(e:Event):void {
stage.addEventListener(Event.ENTER_FRAME, update);
this.removeEventListener(Event.ADDED_TO_STAGE, onAdded);
}
private function update(e:Event):void{
//do the stuff
}