how to use actionscript components code in mmxl components - apache-flex

how i can use actionscript component code in mmxl components,as in actionscript components we use classes ,but in mmxl component we can not use classes function, so how i can use actionscript component code in mmxl component
example,,
this is actionscript component code
package components
{
import assets.*;
import flash.events.*;
import flash.utils.*;
import mx.binding.*;
import mx.containers.*;
import mx.controls.*;
import mx.core.*;
import mx.events.*;
import mx.styles.*;
public class DialogTitle extends HBox implements IBindingClient
{
private var title:String = "TitleDialog";
public var DialogTitle1Image1:Image;
public var DialogTitle2Image2:Image;
public var DialogTitle3Label1:Label;
var _bindingsBeginWithWord:Object;
private var showCloseButton:Boolean = false;
var _bindingsByDestination:Object;
var _watchers:Array;
var _bindings:Array;
private var _documentDescriptor_:UIComponentDescriptor;
private static var _watcherSetupUtil:IWatcherSetupUtil;
but i cant use this code in mmxl components how i can use public class DialogTitle extends HBox implements IBindingClient in mmxl component code,what are the way to use it,sorry i am newbie if it is silly question

Here's how you can derive class from HBox and make it implement interface:
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox
implements="com.interfaces.IBindingClient"
>
<mx:Script>
<![CDATA[
//and code goes here
]]>
</mx:Script>
</mx:HBox>
Note that interface must be specified with full path, imports have no effect on it.

Related

Embedding OSMF (2.0) into a Flex App

I'm trying to emebed a simple OSMF player into my fex application. But it's not working. Here's my code :
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="init()" >
<fx:Script>
<![CDATA[
import org.osmf.media.MediaPlayerSprite;
import org.osmf.media.URLResource;
protected function init():void{
var sprite:MediaPlayerSprite = new MediaPlayerSprite();
sprite.resource= new URLResource("http://mediapm.edgesuite.net/strobe/content/test/AFaerysTale_sylviaApostol_640_500_short.flv");
container.addChild(sprite);
}
]]>
</fx:Script>
<mx:UIComponent id="container" width="640" height="360"/>
I'm having a white screen when running the application
Thanks
here's the pure AS for how to do it:
package {
import flash.display.Sprite;
import org.osmf.media.MediaPlayerSprite;
import org.osmf.media.URLResource;
import org.osmf.media.DefaultMediaFactory;
public class SimpleOSMFPlayer extends flash.display.Sprite {
public static const PATH:String = "path/to/your/video.ext";
public var playerSprite:MediaPlayerSprite;
public var mediaFactory:DefaultMediaFactory;
public function SimpleOSMFPlayer() {
playerSprite = new MediaPlayerSprite();
var resource:URLResource = new URLResource(PATH);
mediaFactory = new DefaultMediaFactory();
playerSprite.media = mediaFactory.createMediaElement(resource);
addChild(playerSprite);
}
}
}
for flex, add the playerSprite to your UIComponent container instead of the sprite on the last line.

Can't figure out why I'm getting an "Access of undefined object" error in Flex 4.5

I'm very new to Flex 4.5 and I created a class (Project.as) with the following code in it:
package classes
{
public class Project
{
public var projectName:String;
public var description:String;
public var fileLoc:String;
public function Project()
{
// This is the constructor
}
public function SayHello() {
import mx.controls.Alert;
Alert.show('howdy!','Greeting');
}
}
}
In my main.mxml file, I have the following code:
<fx:Script>
<![CDATA[
import classes.Project;
import mx.controls.Alert;
public var aProject:Project = new Project;
aProject.SayHello();
]]>
</fx:Script>
And Flex Builder is saying this:
1120: Access of undefined property aProject.
Why is it telling me this, and how can I fix it? I don't see why it's not working.
Lots of issues here.
First, I have never seen anyone put import statements inside a method. Usually they are put between the package and class definition:
package classes
{
import mx.controls.Alert;
public class Project
{
public var projectName:String;
public var description:String;
public var fileLoc:String;
public function Project()
{
// This is the constructor
}
public function SayHello() {
Alert.show('howdy!','Greeting');
}
}
}
Second; the line of ActionSCript code that you write to call a method on your class instance should be placed inside a method; not "random". Like this:
<fx:Script>
<![CDATA[
import classes.Project;
import mx.controls.Alert;
public var aProject:Project = new Project;
protected function sayHello():void{
aProject.SayHello();
}
]]>
</fx:Script>
Some way you'll want to call that method. A commenter on the original post suggested using creationComplete, which would work. However, you should be cautious about using creationComplete for "constructor-style" code in an MXML Component. preinitialize is better, and the event will fire right after the actual constructor runs. If you need to access any MXML children, have your code in an initialize event handler which runs right after createChildren() runs.
creationComplete handlers execute right after the component finishes initializing; and people often do things in creationComplete that make the component go through it's Lifecycle again, updating the display list.

Alert Box Class

I want to make a reusable Alert Box Class which will be instantiated on various screens of my Flex Project.
Can some tell me whats next in the code below, because am sort of lost regarding how to set the message and title and how to call the Class in my project?
Any help.
Thanks
package components
{
import mx.controls.Alert;
import mx.core.mx_internal;
public class myAlertBox extends Alert
{
public function AlertBoza()
{
super();
var a:Alert;
}
override public static function show():void{
}
}
}
You do not need to extend Alert since the Alert.show() function is static. But you can set it as follows inserting a constructor for a message string and a class member. With that cou can just call the class with the constructor and show the alertbox.
package components
{
import mx.controls.Alert;
import mx.core.mx_internal;
public class myAlertBox
{
private var message:String;
public function myAlertBox(message:String = "")
{
super();
this.message = message;
}
public function show():void{
Alert.show(message);
}
}
}
In another class you can call:
var box:myAlertBox = new myAlertBox("Error");
myAlertBox.show();
If you just want to show a simple alert box, just use mx.controls.Alert directly as you can specify the title and the message show then:
import mx.controls.Alert;
Alert.show("the message", "the title");

Bindable variable not updating with viewstack / swiz

I'm using the Swiz framework and I'm trying to update my viewstack's selectedIndex with a bindable property. It gets to my event handler which updates the bindable variable but the Main app file's viewstack never realizes it. What could be the issue?
thx
-Mike
================================
MAIN APP FILE
<mx:Script>
<![CDATA[
import reg.model.ApplicationViewModel;
import beyaz.reg.swiz.SwizBeans;
import org.swizframework.Swiz;
[Autowire(bean="applicationViewModel")]
[Bindable]
public var applicationViewModel:ApplicationViewModel;
private function preInitialize():void {
Swiz.loadBeans( [ SwizBeans ] );
}
]]>
</mx:Script>
<mx:ViewStack id="theViewstack" **selectedIndex=" {applicationViewModel.mainViewIndex}"** width="100%" height="100%">
<prescreen:Prescreen id="prescreenView"/>
<login:Login id="loginView"/>
<profile:Profile id="profileView"/>
</mx:ViewStack>
=================================
ApplicationViewModel
package com.reg.model
{
public class ApplicationViewModel
{
public static const PRESCREEN_VIEW:int = 0;
public static const LOGIN_VIEW:int = 1;
public static const PRSNL_INFO_VIEW:int = 2;
[Bindable]
public var message:String = "";
[Bindable]
public var mainViewIndex:int = PRESCREEN_VIEW;
}
}
===========================
Controller
package com.reg.controller
{
import com.reg.model.ApplicationViewModel;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.DynamicEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.core.Application;
import org.swizframework.Swiz;
import org.swizframework.controller.AbstractController;
public class PrescreenController// extends AbstractController
{
public static const START_REGISTRATION:String = "startReg";
[Autowire(bean="applicationViewModel")]
[Bindable]
public var applicationViewModel:ApplicationViewModel;
[Mediate(event="startReg")]
public function startReg():void
{
//CODE GETS TO HERE!
applicationViewModel.mainViewIndex = ApplicationViewModel.PRSNL_INFO_VIEW;
}
}
}
I got bit by this problem just last week.
Put your [Bindable] tag before the other tags. For some reason the Flex compiler doesn't fold in the appropriate PropertyChangeEvent dispatching unless you put the [Bindable] tag first.

Loading of external SWF results in a "Could not find resource bundle messaging" error

I'm using flash.display.Loader to load this example SWF as a use-case for loading SWFs that uses flex charting components in an application I'm working on.
This is the code I'm using to load the swf:
Main.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="onCreationComplete(event);">
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
import myLoaderClass;
private function onCreationComplete( e:FlexEvent ):void
{
trace("Init!");
var l:myLoaderClass = new myLoaderClass();
this.addChild(l);
}
]]>
</mx:Script>
</mx:Application>
myLoaderClass:
package
{
import mx.core.UIComponent;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.Loader;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.utils.Dictionary;
public class JittRunner extends UIComponent
{
private var displayedObjects:Dictionary;
public function JittRunner():void
{
displayedObjects = new Dictionary();
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest('ChartSampler.swf');
mLoader.load(mRequest);
}
}
}
The thing is, the minute the swf is loaded I'm getting the following runtime error:
Error: Could not find resource bundle messaging
at mx.resources::ResourceBundle$/getResourceBundle()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\resources\ResourceBundle.as:143]
at mx.utils::Translator$cinit()
at global$init()
at mx.messaging.config::ServerConfig$cinit()
at global$init()
at _app_FlexInit$/init()
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::docFrameHandler()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3217]
at mx.managers::SystemManager/docFrameListener()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3069]
What am I doing wrong here?
I don't think you're not doing anything wrong in the code you posted. I just pasted it into a new project (renamed JittRunner to myLoaderClass) and it compiled and ran fine (didn't do anything but no errors).

Resources