how to use this as class code in mmxl aaplication? - apache-flex

I have taken this code from one of my friend,but in real it is totally mess there are plenty of error i am getting by running this code,i have some question
How i can use this code in mxml application,as we know we can not use public class in mx script so what are the way to do that
as you can see .mx_internal,i am getting error on that saying'define object before dot' as i remove mx_internal and tried using import mx.binding.mx_internal and use namespace mx_internal application not desplaying anything
now you will tell me ther are easy methods are ther to solve problem but my whole project is on this method only
thanks for help in advance
i am trying to solve this problem from last 15 days ,with no success,pls help me below is code
package components
{
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 _110371416title:String = "Dialog Title";
public var _DialogTitle_Image1:Image;
public var _DialogTitle_Image2:Image;
public var _DialogTitle_Label1:Label;
var _bindingsBeginWithWord:Object;
private var _1859425293showCloseButton:Boolean = false;
var _bindingsByDestination:Object;
var _watchers:Array;
var _bindings:Array;
private var _documentDescriptor_:UIComponentDescriptor;
private static var _watcherSetupUtil:IWatcherSetupUtil;
public function DialogTitle()
{
_documentDescriptor_ = new UIComponentDescriptor({type:HBox, propertiesFactory:function () : Object
{
return {height:27, childDescriptors:[new UIComponentDescriptor({type:Spacer, propertiesFactory:function () : Object
{
return {width:5};
}// end function
}), new UIComponentDescriptor({type:Image, id:"_DialogTitle_Image1"}), new UIComponentDescriptor({type:Spacer, propertiesFactory:function () : Object
{
return {width:5};
}// end function
}), new UIComponentDescriptor({type:Label, id:"_DialogTitle_Label1", stylesFactory:function () : void
{
this.fontSize = 14;
this.color = 16777215;
this.fontWeight = "bold";
return;
}// end function
}), new UIComponentDescriptor({type:Spacer, propertiesFactory:function () : Object
{
return {percentWidth:100};
}// end function
}), new UIComponentDescriptor({type:Image, id:"_DialogTitle_Image2", events:{click:"___DialogTitle_Image2_click"}, propertiesFactory:function () : Object
{
return {useHandCursor:true, buttonMode:true, mouseChildren:false, toolTip:"Close"};
}// end function
}), new UIComponentDescriptor({type:Spacer, propertiesFactory:function () : Object
{
return {width:13};
}// end function
})]};
}// end function
});
_bindings = [];
_watchers = [];
_bindingsByDestination = {};
_bindingsBeginWithWord = {};
mx_internal::_document = this;
if (!this.styleDeclaration)
{
this.styleDeclaration = new CSSStyleDeclaration();
}
this.styleDeclaration.defaultFactory = function () : void
{
this.backgroundColor = 9947478;
this.horizontalGap = 0;
this.verticalAlign = "middle";
this.verticalGap = 0;
return;
}// end function
;
this.height = 27;
this.percentWidth = 100;
return;
}// end function
private function _DialogTitle_bindingExprs() : void
{
var _loc_1:* = undefined;
_loc_1 = CustomEmbeddedAssets.logoImageSmall;
_loc_1 = title;
_loc_1 = EmbeddedAssets.dialogClose;
_loc_1 = showCloseButton;
return;
}// end function
public function get showCloseButton() : Boolean
{
return this._1859425293showCloseButton;
}// end function
override public function initialize() : void
{
var target:DialogTitle;
var watcherSetupUtilClass:Object;
.mx_internal::setDocumentDescriptor(_documentDescriptor_);
var bindings:* = _DialogTitle_bindingsSetup();
var watchers:Array;
target;
if (_watcherSetupUtil == null)
{
watcherSetupUtilClass = getDefinitionByName("_components_DialogTitleWatcherSetupUtil");
var _loc_2:* = watcherSetupUtilClass;
_loc_2.watcherSetupUtilClass["init"](null);
}
_watcherSetupUtil.setup(this, function (param1:String)
{
return target[param1];
}// end function
, bindings, watchers);
var i:uint;
while (i < bindings.length)
{
Binding(bindings[i]).execute();
i = (i + 1);
}
mx_internal::_bindings = mx_internal::_bindings.concat(bindings);
mx_internal::_watchers = mx_internal::_watchers.concat(watchers);
super.initialize();
return;
}// end function
public function get title() : String
{
return this._110371416title;
}// end function
private function _DialogTitle_bindingsSetup() : Array
{
var binding:Binding;
var result:Array;
binding = new Binding(this, function () : Object
{
return CustomEmbeddedAssets.logoImageSmall;
}// end function
, function (param1:Object) : void
{
_DialogTitle_Image1.source = param1;
return;
}// end function
, "_DialogTitle_Image1.source");
result[0] = binding;
binding = new Binding(this, function () : String
{
var _loc_1:* = title;
var _loc_2:* = _loc_1 == undefined ? (null) : (String(_loc_1));
return _loc_2;
}// end function
, function (param1:String) : void
{
_DialogTitle_Label1.text = param1;
return;
}// end function
, "_DialogTitle_Label1.text");
result[1] = binding;
binding = new Binding(this, function () : Object
{
return EmbeddedAssets.dialogClose;
}// end function
, function (param1:Object) : void
{
_DialogTitle_Image2.source = param1;
return;
}// end function
, "_DialogTitle_Image2.source");
result[2] = binding;
binding = new Binding(this, function () : Boolean
{
return showCloseButton;
}// end function
, function (param1:Boolean) : void
{
_DialogTitle_Image2.visible = param1;
return;
}// end function
, "_DialogTitle_Image2.visible");
result[3] = binding;
return result;
}// end function
public function set showCloseButton(param1:Boolean) : void
{
var _loc_2:* = this._1859425293showCloseButton;
if (_loc_2 !== param1)
{
this._1859425293showCloseButton = param1;
this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "showCloseButton", _loc_2, param1));
}
return;
}// end function
public function ___DialogTitle_Image2_click(event:MouseEvent) : void
{
dispatchEvent(new Event("onCancel"));
parent.visible = false;
return;
}// end function
public function set title(param1:String) : void
{
var _loc_2:* = this._110371416title;
if (_loc_2 !== param1)
{
this._110371416title = param1;
this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "title", _loc_2, param1));
}
return;
}// end function
public static function set watcherSetupUtil(param1:IWatcherSetupUtil) : void
{
DialogTitle._watcherSetupUtil = param1;
return;
}// end function
}
}

Just throw this code out. This code was generated automatically by mxmlc compiler from MXML class and can't be used in production. It is for computer, not for humans. Write the right code by yourself. I hope it will be clearer and maintainable. And yes, this code wasn't written by your friend :)

This file is decompiled from a .mxml file, which use tags to describe layout. However, some decompiler can't convert it completely, and you will see file like this.
As you see, the argument of UIComponentDescriptor is an object, which contains a lot of key-val pairs. It has some type of keys:
type:Class --> this is the type of this component, which is the node tag of .mxml file
id:String --> this is the ID of a node, which is also the variable name you can use in <fx:Script> tag
event:Object --> events that the component will trigger
stylesFactory:Function --> component's styles setting
propertiesFactory:Function --> contains some properties and child nodes
code like this:
<mx:Canvas id="mainCanvas" borderStyle="none" label="main">
<mx:Button click="onClick(event)" />
</mx:Canvas>
will be converted into:
new UIComponentDescriptor({
"type":Canvas,
"id":mainCanvas,
"styleFactory":function():void {
this.borderStyle="none";
},
"propertiesFactory":function():Object {
return({
"label":"main"
"childDescriptors":[new UIComponentDescriptor({
// button's code in here
});
]
})
}
})
For those events:
As you can write click event in mxml tags both like btnOnClick() and btnOnClick(event), the compiler need to do something to ensure the event handler accept a right argument. So, for the Button tag I just mention, the
value corresponding to key"event" will be like this: {"click":"__on_click"}. Then the compiler will create a new function call __on_click, which may like this:
public function __on_click(event:MouseEvent):void {
onClick(event);
}
Obviously, after you convert the UIComponentDescriptor into .mxml, you should replace the events function.
For the constructor:
.mxml file can not has a constructor, but the compiler will create one in .as file, which contains the UIComponentDescriptor. The constructor will also do some initialization for it's variables. When converting to .mxml file, you need to do this initialization after the variable's declaration.
For example:
public function MyCanvas(){
this._documentDescriptor_ = new UIComponentDescriptor({
//……
});
this.myArray = new Array();
}
you should convert it into this:
<fx:Script><![CDATA[
var myArray:Array = new Array();
]]></fx:Script>
So the heaviest work is to convert UIComponentDescriptor into .mxml tags. And here is a simple python script that can help you do it:
UIComponentDescriptor2XML

Related

dispatch event not fired in action script 2.0

I have created a class named CheckBoxSelectAll in which I am triggering an event as below.
import mx.events.EventDispatcher;
import flash.filters.GlowFilter;
class CheckBoxSelectAll
{
public function dispatchEvent() {};
public function addEventListener() {};
public function removeEventListener() {};
private var checkbox_mc:MovieClip;
private var parent_mc:MovieClip;
function CheckBoxSelectAll()
{
mx.events.EventDispatcher.initialize(this);
}
function CreateCheckBox(c_mc:MovieClip)
{
var labelGlow:GlowFilter = new GlowFilter(0xFFFFFF, .30, 4, 4, 3, 3);
var labelFilters:Array = [labelGlow];
this.parent_mc = c_mc;
checkbox_mc = parent_mc.createEmptyMovieClip("",this.checkbox_mc.getNextHighestDepth() );
checkbox_mc._x =450;// boxX;
checkbox_mc._y =143;// boxY;
checkbox_mc.lineStyle(1, 0);
checkbox_mc.beginFill(currentFill, currentAlpha);
checkbox_mc.moveTo(0, triSize);
checkbox_mc.lineTo(triSize, triSize);
checkbox_mc.lineTo(triSize, 0);
checkbox_mc.lineTo(0, 0);
checkbox_mc.lineTo(0, triSize);
checkbox_mc.endFill();
checkbox_mc._visible = true;
checkbox_mc.onPress = function() {
var eventObject:Object = {target:this, type:'onDataReady'};
dispatchEvent(eventObject);
trace("OnPress refresh...");
}
}
}
In Parent movie clip, used following code
var select_all_listener:Object = new Object();
select_all_listener.onDataReady = triggerDisksLoad;
var select_all_box:CheckBoxSelectAll;
select_all_box = new CheckBoxSelectAll();
select_all_box.addEventListener("onDataReady", select_all_listener);
select_all_box.CreateCheckBox(this);
function triggerDisksLoad(evtObj) { trace("triggerDisksLoad called...!!!"); }
Here function triggerDisksLoad is not called.
The problem of your code is the scope where the checkbox_mc.onPress handler is executed, to avoid that, you can use the Delegate class, like this :
import mx.events.EventDispatcher;
import mx.utils.Delegate;
class CheckBoxSelectAll extends MovieClip
{
// ...
function CreateCheckBox(c_mc:MovieClip)
{
// ...
checkbox_mc.onPress = Delegate.create(this, _onPress);
}
private function _onPress():Void {
var event:Object = {target: this, type: 'onDataReady'};
dispatchEvent(event);
}
}
Also for the new MovieClips creation, when we use getNextHighestDepth(), it's usually used with the parent of the new MovieClip, so you can write :
checkbox_mc = parent_mc.createEmptyMovieClip('mc_name', parent_mc.getNextHighestDepth());
Hope that can help.

Add "New item Label" to Spark ComboBox

I have a Custom Spark ComboBox which contains a list of items. I want to Add a new Item to the ComboBox stating the text "Add new Item", which on selecting popup a window to do some operations.
I have achieved this by creating a new object of the same type of the entities in the data provider, with the LabelField of the new object having the text "Add new Item". I have override the set dataProvider method and in the custom combobox.
But this adds the values to the Actual List which is binded to the DataProvider. The list is used in the business logics. So i do not want this to happen. I have lot of Entity Classes. i could not change all the objects.
All i want is to achieve the same functionality in my custom component without changing the other code. I have also tried to create a new instance of dataProvier but i noticed that the binding of the List and dataprovider is lost when i created a new instance.
Kindly help.!!
Edited:
ExtendedComboBox.as
package components
{
import flash.utils.getDefinitionByName;
import mx.collections.ArrayCollection;
import mx.collections.IList;
import spark.components.ComboBox;
import spark.events.DropDownEvent;
public class ExtendedComboBox extends ComboBox
{
private var _addItem:Boolean = false;
private var _addItemLabel:String = "Create New Item" ;
private var _dropDownClass:String = null ;
private var originalDP:IList ;
private var dpEdited:Boolean = false;
public function ExtendedComboBox()
{
super();
this.addItem = true;
this.addEventListener(DropDownEvent.CLOSE, dropDownCloseEventListner );
this.addEventListener(DropDownEvent.OPEN, openDropDownEvent );
}
public function get dropDownClass():String
{
return _dropDownClass;
}
public function set dropDownClass(value:String):void
{
_dropDownClass = value;
}
public function get addItemLabel():String
{
return _addItemLabel;
}
public function set addItemLabel(value:String):void
{
_addItemLabel = value;
}
public function get addItem():Boolean
{
return _addItem;
}
public function set addItem(value:Boolean):void
{
_addItem = value;
}
private function dropDownCloseEventListner(event:DropDownEvent):void{
}
protected function openDropDownEvent(event:DropDownEvent):void{
if(addItem)
{
// if(value) value = new ArrayCollection();
var value:IList ;
if(originalDP == null) value = new ArrayCollection ;
else value = new ArrayCollection( originalDP.toArray() ) ;
var tempObj:Object;
var createItemPresent:Boolean =false ;
if(dropDownClass != null)
{
var TempClass = flash.utils.getDefinitionByName(dropDownClass) as Class;
tempObj = new TempClass();
if(value.length >0)
{
// trace(value.getChildAt(0)[this.labelField]) ;
if(value.getItemAt(0)[this.labelField] == addItemLabel)
createItemPresent = true ;
}
if(!createItemPresent)
{
tempObj[this.labelField] = addItemLabel ;
var sort = (value as ArrayCollection).sort ;
value.addItemAt(tempObj, 0);
(value as ArrayCollection).sort = sort ;
dpEdited = true;
}
}
}
super.dataProvider = value;
}
override public function set dataProvider(value:IList):void{
if(!dpEdited)
{
originalDP = value;
dpEdited = true;
}
/*if(addItem)
{
// if(value) value = new ArrayCollection();
var tempObj:Object;
var createItemPresent:Boolean =false ;
if(dropDownClass != null)
{
var TempClass = flash.utils.getDefinitionByName(dropDownClass) as Class;
tempObj = new TempClass();
if(value.length >0)
{
if(value.getItemIndex(0)[this.labelField] == addItemLabel)
createItemPresent = true ;
}
if(!createItemPresent)
{
tempObj[this.labelField] = addItemLabel ;
var sort = (value as ArrayCollection).sort ;
value.addItemAt(tempObj, 0);
(value as ArrayCollection).sort = sort ;
}
}
}*/
super.dataProvider = value;
}
}
}
MyEntityObj.as
package entity
{
public class MyEntityObj
{
private var _name:String ;
private var _age:int ;
private var _company:String;
public function MyEntityObj()
{
}
public function get company():String
{
return _company;
}
public function set company(value:String):void
{
_company = value;
}
public function get age():int
{
return _age;
}
public function set age(value:int):void
{
_age = value;
}
public function get name():String
{
return _name;
}
public function set name(value:String):void
{
_name = value;
}
}
}
And Implementation Sample - ComboImpl.mxml
<?xml version="1.0" encoding="utf-8"?>
import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;
import mx.events.FlexEvent;
[Bindable]
private var samplDP:ArrayCollection;
protected function application1_initializeHandler(event:FlexEvent):void
{
samplDP = new ArrayCollection ;
samplDP.addEventListener(CollectionEvent.COLLECTION_CHANGE, changeHandlerFunc );
var sampVO:MyEntityObj;
for(var i:int = 0; i<5;i++)
{
sampVO = new MyEntityObj;
sampVO.name = "Name " + i;
sampVO.age = i;
sampVO.company = "Company " + i;
samplDP.addItem(sampVO);
}
}
protected function changeHandlerFunc(event:CollectionEvent):void{
var nameList:String = "" ;
for each(var myObj:* in samplDP)
{
nameList += myObj.name + ", " ;
}
changeHandler.text = nameList ;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:VGroup>
<s:Label id="changeHandler" />
<components:ExtendedComboBox dataProvider="{samplDP}" labelField="name" addItem="true" dropDownClass="entity.MyEntityObj" addItemLabel="Create Sample" />
</s:VGroup>
As commented in the set DataProvider Overridden method and the in the DropDownClose events addition of the new item directly affects the original List. i do not want this to happen.
Note that its just a sample implementation. The component creation in my project actually happens in the action script class dynamically.
Kindly help.!!
It sounds to me like:
You're going to have to extend the ComboBox (If you drill down into how it's implemented, possibly the DataGroup) to include your extra "Add New Item" item w/o it being in the dataProvider.
I expect this to be very difficult, but have not reviewed the code for this purpose.

override public function initialize() error in flex

i want to know what i should put befor .mx_internal
override public function initialize() : void
{
var target:DialogButtons;
var watcherSetupUtilClass:Object;
.mx_internal::setDocumentDescriptor(_documentDescriptor_);
var bindings:* = _DialogButtons_bindingsSetup();
var watchers:Array;
target;
if (_watcherSetupUtil == null)
{
watcherSetupUtilClass = getDefinitionByName("_components_DialogButtonsWatcherSetupUtil");
var obj1:* = watcherSetupUtilClass;
obj1.watcherSetupUtilClass["init"](null);
}
_watcherSetupUtil.setup(this, function (param1:String)
{
return target[param1];
}// end function
, bindings, watchers);
var i:uint;
while (i < bindings.length)
{
Binding(bindings[i]).execute();
i = (i + 1);
}
mx_internal::_bindings = mx_internal::_bindings.concat(bindings);
mx_internal::_watchers = mx_internal::_watchers.concat(watchers);
super.initialize();
return;
}// end function
mx_internal should be without dot.
You don't have to reference the mx_internal namespace every time you access it. You can just import it into the class. Use statements like this:
import mx.core.mx_internal;
use namespace mx_internal;
Then re-write your code like this:
override public function initialize() : void
{
var target:DialogButtons;
var watcherSetupUtilClass:Object;
// line commented to snow the mx_internal less code
// .mx_internal::setDocumentDescriptor(_documentDescriptor_);
setDocumentDescriptor(_documentDescriptor_);
var bindings:* = _DialogButtons_bindingsSetup();
var watchers:Array;
target;
if (_watcherSetupUtil == null)
{
watcherSetupUtilClass = getDefinitionByName("_components_DialogButtonsWatcherSetupUtil");
var obj1:* = watcherSetupUtilClass;
obj1.watcherSetupUtilClass["init"](null);
}
_watcherSetupUtil.setup(this, function (param1:String)
{
return target[param1];
}// end function
, bindings, watchers);
var i:uint;
while (i < bindings.length)
{
Binding(bindings[i]).execute();
i = (i + 1);
}
// lines commented to snow the mx_internal less code
// mx_internal::_bindings = mx_internal::_bindings.concat(bindings);
// mx_internal::_watchers = mx_internal::_watchers.concat(watchers);
_bindings = _bindings.concat(bindings);
_watchers = _watchers.concat(watchers);
super.initialize();
return;
}// end function

Manually dispatch a collection change event

I have a standard combobox that dispatches a collection event when the dataprovider finishes initializing:
my_cb.addEventListener( CollectionEvent.COLLECTION_CHANGE, getMyStuff );
Then I have a custom component that also has a dataProvider. How do I get it to dispatch a collection change event when its dataprovider finishes loading?
From what I've read, I can't do it. Will dispatching a propertychangeevent work?
Thanks for any helpful tips!
UPDATE:
I have a custom component that I call 'SortingComboBox' but it is not a ComboBox at all; it extends Button and I set is dataProvider property to my arraycollection, model.product (which is an arraycollection).
And here is how I use the dataProvider in that component:
code
[Bindable]
private var _dataProvider : Object;
public function get dataProvider() : Object
{
return _dataProvider;
}
public function set dataProvider(value : Object) : void
{
_dataProvider = value;
}
code
In the createChildren() method of this component, I use this:
BindingUtils.bindProperty(dropDown, "dataProvider", this, "dataProvider");
The dropDown is a custom VBox that I use to display labels.
When you call the setter, you have to make sure
1) that you actually are changing the value with the setter. So even if you are inside the class, call this.dataProvider = foo instead of _dataProvider = foo
2) The binding will not trigger unless you actually change the value. If you trace you'll see that the setter actually calls the getter, if the values of what you pass into the setter and the getter are the same, the binding will not occur.
Your other option is to put an event on the getter, then just call it to trigger the binding.
[Bindable( "somethingChanged" )]
public function get dataProvider() : Object
{
return _dataProvider;
}
dispatchEvent( new Event( "somethingChanged" ) );
Make your dataprovider bindable
[Bindable]
protected var _dataProvider:ArrayCollection ;
Data binding is something unique to ActionScript/Flex.
Among other things it will dispatch change events.
Maybe if you post your code for the custom component I can be more specific.
Actually can you explain what your goal is you are trying to achieve?
All I can tell is you are trying to make a button have a drop down.
Why?
this is the custom component just to give you a better idea.
code
package com.fidelity.primeservices.act.components.sortingcombobox
{
import com.fidelity.primeservices.act.events.component.ResetSortEvent;
import com.fidelity.primeservices.act.events.component.SortEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.geom.Rectangle;
import mx.binding.utils.BindingUtils;
import mx.controls.Button;
import mx.core.UIComponent;
import mx.effects.Tween;
import mx.events.FlexMouseEvent;
import mx.managers.PopUpManager;
import mx.events.PropertyChangeEvent;
import mx.events.PropertyChangeEventKind;
public class SortingComboBox extends Button
{
private const MAX_LABEL_LENGTH : int = 400;
private const ELIPSES : String = "...";
[Bindable]
private var _dataProvider : Object;
private var dropDown : SortingDropDown;
private var inTween : Boolean;
private var showingDropdown : Boolean;
private var openCloseTween : Tween;
public var noSelectionLabel : String = "No Filter";
public var noSelectionData : String = "ALL";
public function get dataProvider() : Object
{
return _dataProvider;
}
public function set dataProvider(value : Object) : void
{
_dataProvider = value;
}
private function collectionEvent(e : Event):void
{
trace(new Date(), e);
}
public function SortingComboBox()
{
super();
this.buttonMode = true;
this.useHandCursor = true;
inTween = false;
showingDropdown = false;
addEventListener(Event.REMOVED_FROM_STAGE, removedFromStage);
}
override protected function createChildren() : void
{
super.createChildren();
dropDown = new SortingDropDown();
dropDown.width = 240;
dropDown.maxHeight = 300;
dropDown.visible = false;
BindingUtils.bindProperty(dropDown, "dataProvider", this, "dataProvider");
dropDown.styleName = "sortingDropDown";
dropDown.addEventListener(SortEvent.CLOSE_SORT, closeDropDown);
dropDown.addEventListener(FlexMouseEvent.MOUSE_DOWN_OUTSIDE, dropdownCheckForClose);
dropDown.addEventListener(FlexMouseEvent.MOUSE_WHEEL_OUTSIDE, dropdownCheckForClose);
dropDown.addEventListener(SortEvent.UPDATE_SORT, onSortUpdate); //this event bubbles
dropDown.addEventListener(ResetSortEvent.RESET_SORT_EVENT, onSortUpdate);
PopUpManager.addPopUp(dropDown, this);
this.addEventListener(MouseEvent.CLICK, toggleDropDown);
// weak reference to stage
systemManager.addEventListener(Event.RESIZE, stageResizeHandler, false, 0, true);
}
private function stageResizeHandler(evt : Event) : void
{
showingDropdown = false;
dropDown.visible = showingDropdown;
}
private function toggleDropDown(evt : MouseEvent) : void
{
if(!dropDown.visible)
{
openDropDown(evt);
}
else
{
closeDropDown(evt);
}
}
private function openDropDown(evt : MouseEvent) : void
{
if (dropDown.parent == null) // was popped up then closed
{
PopUpManager.addPopUp(dropDown, this);
}
else
{
PopUpManager.bringToFront(dropDown);
}
showingDropdown = true;
dropDown.visible = showingDropdown;
dropDown.enabled = false;
var point:Point = new Point(0, unscaledHeight);
point = localToGlobal(point);
point = dropDown.parent.globalToLocal(point);
//if the dropdown is larger than the button and its
//width would push it offscreen, align it to the left.
if (dropDown.width > unscaledWidth && point.x + dropDown.width > screen.width)
{
point.x -= dropDown.width - unscaledWidth;
}
dropDown.move(point.x, point.y);
//run opening tween
inTween = true;
// Block all layout, responses from web service, and other background
// processing until the tween finishes executing.
UIComponent.suspendBackgroundProcessing();
dropDown.scrollRect = new Rectangle(0, dropDown.height, dropDown.width, dropDown.height);
openCloseTween = new Tween(this, dropDown.height, 0, 250);
}
private function closeDropDown(evt : Event) : void
{
//dropDown.visible = false;
showingDropdown = false;
//run closing tween
inTween = true;
// Block all layout, responses from web service, and other background
// processing until the tween finishes executing.
UIComponent.suspendBackgroundProcessing();
openCloseTween = new Tween(this, 0, dropDown.height, 250);
}
private function dropdownCheckForClose(event : MouseEvent) : void
{
if (event.target != dropDown)
// the dropdown's items can dispatch a mouseDownOutside
// event which then bubbles up to us
return;
if (!hitTestPoint(event.stageX, event.stageY, true))
{
closeDropDown(event);
}
}
public function refresh():void
{
onSortUpdate(null);
}
private function onSortUpdate(evt1 : Event) : void
{
//update the label
var dpLength : int = this.dataProvider.length;
var nextLabel : String = "";
var nextData : String = "";
for (var i : int = 0; i < dpLength; i++)
{
if (this.dataProvider[i].selected == true)
{
nextLabel += this.dataProvider[i].label + ", ";
if (this.dataProvider[i].data != null)
{
nextData += this.dataProvider[i].data + ", ";
}
}
}
if (nextLabel.length > 0)
{
// remove extra comma at end
nextLabel = nextLabel.substr(0, nextLabel.length - 2);
}
if (nextData.length > 0)
{
nextData = nextData.substr(0, nextData.length - 2);
}
if (nextLabel.length > MAX_LABEL_LENGTH)
{
// limit label to MAX_LABEL_LENGTH + ... REASON: tooltips with lots of characters take a long time to render
nextLabel = nextLabel.substr(0, MAX_LABEL_LENGTH) + ELIPSES;
}
if (nextLabel.length == 0)
{
nextLabel = noSelectionLabel;
//nextLabel = "No Filter";
}
if (nextData.length == 0)
{
nextData = noSelectionData;
//nextData = "ALL";
}
label = nextLabel;
data = nextData;
toolTip = label;
if (evt1 is SortEvent)
{
trace("sort event");
var temp:Object = this.dataProvider;
this.dataProvider = null;
this.dataProvider = temp;
this.refresh();
}
else
{
trace("not dispatching");
}
}
public function onTweenUpdate(value:Number):void
{
dropDown.scrollRect = new Rectangle(0, value, dropDown.width, dropDown.height);
}
public function onTweenEnd(value:Number) : void
{
// Clear the scrollRect here. This way if drop shadows are
// assigned to the dropdown they show up correctly
dropDown.scrollRect = null;
inTween = false;
dropDown.enabled = true;
dropDown.visible = showingDropdown;
UIComponent.resumeBackgroundProcessing();
}
private function removedFromStage(event:Event):void
{
if(inTween)
{
openCloseTween.endTween();
}
// Ensure we've unregistered ourselves from PopupManager, else
// we'll be leaked.
PopUpManager.removePopUp(dropDown);
}
}
}
Ok this code here
[Bindable]
private var _dataProvider : Object;
public function get dataProvider() : Object
{
return _dataProvider;
}
public function set dataProvider(value : Object) : void
{
_dataProvider = value;
}
is no different then
[Bindable]
public var _dataProvider : Object;
Since objects are passed by reference you are not protecting it in anyway and the setter and getter are pointless.
On the other hand you made the source _dataProvider Bindable so anytime the data changes it will dispatch a CollectionEvent.COLLECTION_CHANGE

adobe startus text chat broken # connection setup

Hello the problem i'm experiencing is when I attempt to call javascript function.
Using Jquery #
$("#flashtxtchat").get(0).startTxtChat()
ArgumentError: Error #2126:
NetConnection object must be
connected. at
flash.net::NetConnection/get nearID()
at textchat/startChat() at
Function/http://adobe.com/AS3/2006/builtin::apply()
at
flash.external::ExternalInterface$/_callIn()
at ()
List item
<![CDATA[
import flash.events.*;
import flash.external.*;
import flash.net.*;
import flash.system.*;
import mx.containers.*;
import mx.controls.*;
import mx.core.*;
import mx.events.*;
import mx.styles.*;
import mx.utils.*;
private var netConnection:NetConnection;
private var sendStream:NetStream;
private var receiveStream:NetStream;
private var strangerPeerID:String;
public function init() : void
{
var url:* = FlexGlobals.topLevelApplication.url;
var serverName:* = URLUtil.getServerName(url);
if (!serverName.match(/(localhost|127.0.0.1)$/))
{
return;
}
ExternalInterface.addCallback("startTxtChat", this.startChat);
ExternalInterface.addCallback("gotStrangerPeerID", this.gotStrangerPeerID);
ExternalInterface.addCallback("sendMsg", this.sendMsg);
ExternalInterface.addCallback("stopTxtChat", this.stopChat);
ExternalInterface.call("flashtxtChat_init");
return;
}// end function
public function startChat() : void
{
if (this.netConnection)
{
ExternalInterface.call("flashtxtChat_gotNearID", this.netConnection.nearID);
}
else
{
this.netConnection = new NetConnection();
this.netConnection.addEventListener(NetStatusEvent.NET_STATUS, this.netConnectionHandler);
this.netConnection.connect("rtmfp://stratus.rtmfp.net/removed-removed/");
}
return;
}// end function
public function gotStrangerPeerID(param1:String) : void
{
var _loc_3:NetStream = null;
this.strangerPeerID = param1;
var _loc_2:int = 0;
while (_loc_2 < this.sendStream.peerStreams.length)
{
_loc_3 = this.sendStream.peerStreams[_loc_2];
if (_loc_3.farID != this.strangerPeerID)
{
_loc_3.close();
}
_loc_2++;
}
this.receiveStream = new NetStream(this.netConnection, this.strangerPeerID);
this.receiveStream.play("textchat");
this.receiveStream.client = this;///temp added by me
//this.strangerVideo.attachNetStream(this.receiveStream);
return;
}// end function
public function sendMsg(msg: String) : void
{
sendStream.send("recvMsg", msg);
}
public function recvMsg(msg: String) : void
{
ExternalInterface.call("recvMsg", msg);
}
public function stopChat() : void
{
this.strangerPeerID = null;
return;
}// end function
public function netConnectionHandler(event:NetStatusEvent) : void
{
var c:Object;
var event:* = event;
switch(event.info.code)
{
case "NetConnection.Connect.Success":
{
c = new Object();
c.onPeerConnect = function (param1:NetStream) : Boolean
{
if (strangerPeerID == null)
{
return true;
}
return param1.farID == strangerPeerID;
};// end function
this.sendStream = new NetStream(this.netConnection, NetStream.DIRECT_CONNECTIONS);
this.sendStream.client = c;
this.sendStream.publish("textchat");
ExternalInterface.call("flashtxtChat_gotNearID", this.netConnection.nearID);
break;
}
case "NetConnection.Connect.Failed":
{
this.netConnection = null;
ExternalInterface.call("flashCb_errorConnectingToStratus");
break;
}
case "NetConnection.Connect.Closed":
{
this.netConnection = null;
this.sendStream.close();
this.sendStream = null;
if (this.receiveStream)
{
this.receiveStream.close();
this.receiveStream = null;
}
break;
}
default:
{
break;
}
}
return;
}// end function
]]>
</mx:Script>
What can be the problem? Thank you I've used a similar implementation for video chat which works flawlessly I just removed all video related functions and only left in text chat now it doesn't work?
check player settings they reset after update allow local p2p

Resources