Sunday, March 28, 2010

Bizarre TileList problem in AIR that...

In my application I have some drag and drop tilelist's however I have only just discovered that if I attempt to drag an item in any of the tilelists and drop it directly onto, or usually slightly just below itself i get a very strange error:-

''Error #1009: Cannot access a property or method of a null object reference.''

The bizzare thing is this exact code works fine within a flex application but the error gets produced within an AIR app. It's the only error I get in my whole application so it's a complete nightmare. One thing I've noticed is that if you drop an item onto itself within Flex a sort of zoom animation of the item occurs but this same animation doesn't sem to occur in AIR apps so I'm wondering if it is this that is causing the problem but other than that I'm totally baffled:-

%26lt;?xml version=''1.0'' encoding=''utf-8''?%26gt;

%26lt;mx:WindowedApplication

xmlns:mx=''http://www.adobe.com/2006/mxml'' layout=''absolute'' creationComplete=''initprofile1NewsAndSportSO()''

%26gt;

%26lt;mx:Script%26gt;

%26lt;![CDATA[

[

Bindable

]

[

Embed(source=''assets/images/bbcnews_small.png''

)]

public var

image1:Class;

[

Bindable

]

[

Embed(source=''assets/images/itv_small.png''

)]

public var

image2:Class;

[

Bindable

]

[

Embed(source=''assets/images/skynews_small.png''

)]

public var

image3:Class;

]]%26gt;

%26lt;/mx:Script%26gt;

%26lt;mx:Script%26gt;

%26lt;![CDATA[

import

mx.collections.*;

import

flash.net.SharedObject;

public var

profile1NewsAndSportSO:SharedObject;

private var profile1NewsAndSportaddLinksFullAC:ArrayCollection = new

ArrayCollection([

{link:

''www.bbcnews.com'', label:''BBC News'', icon:''image1'', largeImage:''assets/images/bbcnews_small.png'', title:''BBC News'', description:''BBC News description will go here''

},

{link:

''www.itv.com/'', label:''ITV'', icon:''image2'', largeImage:''assets/images/itv_small.png'', title:''ITV'', description:''ITV Description will go here''

},

{link:

''www.skynews.com'', label:''Sky News'', icon:''image3'', largeImage:''assets/images/skynews_small.png'', title:''Sky News'', description:''Sky News Description will go here''

}

]);

private var profile1NewsAndSportaddLinksAC:ArrayCollection = new

ArrayCollection([

{link:

''www.bbcnews.com'', label:''BBC News'', icon:''image1'', largeImage:''assets/images/bbcnews_small.png'', title:''BBC News'', description:''BBC News description will go here''

},

{link:

''www.itv.com/'', label:''ITV'', icon:''image2'', largeImage:''assets/images/itv_small.png'', title:''ITV'', description:''ITV Description will go here''

},

{link:

''www.skynews.com'', label:''Sky News'', icon:''image3'', largeImage:''assets/images/skynews_small.png'', title:''Sky News'', description:''Sky News Description will go here''

}

]);

private function profile1NewsAndSportReset():void

{

resetprofile1NewsAndSportAC();

profile1NewsAndSportAddLinksTilelist.dataProvider

= profile1NewsAndSportaddLinksAC;

profile1NewsAndSportLinkChoice.dataProvider =

new

ArrayCollection([]);

}

private function resetprofile1NewsAndSportAC():void

{

profile1NewsAndSportaddLinksAC.removeAll();

for each(var obj:Object in

profile1NewsAndSportaddLinksFullAC){

profile1NewsAndSportaddLinksAC.addItem(obj);

}

}

private function initprofile1NewsAndSportSO():void

{

profile1NewsAndSportSO = SharedObject.getLocal(

''profile1NewsAndSport''

);

if

(profile1NewsAndSportSO.size %26gt; 0){

if

(profile1NewsAndSportSO.data.profile1NewsAndSportaddList){

if(profile1NewsAndSportSO.data.profile1NewsAndSportaddList != ''empty''

){

var profile1NewsAndSportaddList:Array = profile1NewsAndSportSO.data.profile1NewsAndSportaddList.split('',''

);

var profile1NewsAndSporttempAC1:ArrayCollection = new

ArrayCollection();

for each(var str:String in

profile1NewsAndSportaddList){

for each(var obj1:Object in

profile1NewsAndSportaddLinksAC){

if

(str == obj1.label){

profile1NewsAndSporttempAC1.addItem(obj1);

continue

;

}

}

}

if

(profile1NewsAndSporttempAC1.length %26gt; 0){

profile1NewsAndSportAddLinksTilelist.dataProvider = profile1NewsAndSporttempAC1;

}

}

}

if

(profile1NewsAndSportSO.data.profile1NewsAndSportchoiceList){

var profile1NewsAndSportchoiceList:Array = profile1NewsAndSportSO.data.profile1NewsAndSportchoiceList.split('',''

);

var profile1NewsAndSporttempAC2:ArrayCollection = new

ArrayCollection();

for each(var str2:String in

profile1NewsAndSportchoiceList){

for each(var obj2:Object in

profile1NewsAndSportaddLinksAC){

if

(str2 == obj2.label){

profile1NewsAndSporttempAC2.addItem(obj2);

continue

;

}

}

}

if

(profile1NewsAndSporttempAC2.length %26gt; 0){

profile1NewsAndSportLinkChoice.dataProvider = profile1NewsAndSporttempAC2;

}

}

}

else

{

profile1NewsAndSportReset();

}

}

]]%26gt;

%26lt;/mx:Script%26gt;

%26lt;mx:TileList id=''profile1NewsAndSportAddLinksTilelist'' fontWeight=''bold'' dragEnabled=''true'' dragMoveEnabled=''true'' dropEnabled=''true'' height=''292'' width=''650'' left=''21'' columnCount=''5'' rowHeight=''145'' columnWidth=''125'' itemClick=''titleLabel.text=profile1NewsAndSportAddLinksTilelist.selectedItem.ti tle; websiteLinkLabel.text=profile1NewsAndSportAddLinksTilelist.selectedItem.link; descLabel.text=profile1NewsAndSportAddLinksTilelist.selectedItem.description; linkImage.source=profile1NewsAndSportAddLinksTilelist.selectedItem.largeImage;'' itemDoubleClick=''{navigateToURL(new URLRequest('http://' + profile1NewsAndSportAddLinksTilelist.selectedItem.link))}'' doubleClickEnabled=''true'' backgroundColor=''#000000'' borderColor=''#FFFFFF'' color=''#FFFFFF'' borderSides=''top right left'' y=''25''/%26gt;

%26lt;mx:Canvas id=''SitePreviewArea'' y=''10'' width=''453'' height=''540'' backgroundColor=''#545050'' cornerRadius=''20'' borderStyle=''solid'' x=''692'' borderThickness=''2'' dropShadowEnabled=''true'' borderColor=''#000000''

%26gt;

%26lt;mx:Label x=''45'' y=''309'' text=''Website Name:'' width=''150'' height=''52'' fontSize=''14'' fontWeight=''bold'' color=''#FFFFFF'' left=''10''/%26gt;

%26lt;mx:Label x=''150.5'' y=''309'' id=''titleLabel'' width=''282.5'' height=''24'' fontWeight=''bold'' fontSize=''14'' color=''#FCFF00''

/%26gt;

%26lt;mx:Label x=''124.5'' y=''385'' text=''Website Description:'' width=''200'' height=''24'' fontSize=''14'' fontWeight=''bold'' color=''#FFFFFF'' textAlign=''center''/%26gt;

%26lt;mx:TextArea x=''16'' y=''417'' id=''descLabel'' width=''421'' height=''69'' textAlign=''left'' color=''#FCFF00'' borderThickness=''0'' backgroundColor=''#545050'' editable=''false'' enabled=''true'' disabledColor=''#FFFFFF'' backgroundDisabledColor=''#545050'' fontWeight=''bold'' fontSize=''12''

/%26gt;

%26lt;mx:Label x=''61'' y=''342'' text=''Website Link:'' width=''150'' height=''52'' fontSize=''14'' fontWeight=''bold'' color=''#FFFFFF'' left=''10''

/%26gt;

%26lt;mx:TextArea x=''150.5'' y=''343'' id=''websiteLinkLabel'' width=''282.5'' height=''33'' fontWeight=''bold'' fontSize=''12'' color=''#FCFF00'' borderThickness=''0'' backgroundColor=''#545050'' editable=''false'' enabled=''true'' disabledColor=''#FCFF00'' backgroundDisabledColor=''#545050''

/%26gt;

%26lt;mx:Button id=''goToSiteButton'' top=''494'' left=''168'' label=''VISIT SITE'' fontWeight=''bold'' fontSize=''14'' color=''#000000'' click=''{navigateToURL(new URLRequest('http://' + websiteLinkLabel.text))}'' fillAlphas=''[1.0, 1.0]'' fillColors=''[#FFFFFF, #DCDCDC]'' borderColor=''#000000''

/%26gt;

%26lt;mx:Canvas x=''99.5'' y=''51'' width=''250'' height=''250'' backgroundColor=''#FFFFFF''

%26gt;

%26lt;mx:Image id=''linkImage'' click=''{navigateToURL(new URLRequest('http://' + websiteLinkLabel.text))}'' width=''250'' height=''250'' x=''0'' y=''0'' scaleContent=''true'' top=''2'' right=''2'' left=''2'' bottom=''2''

/%26gt;

%26lt;/mx:Canvas%26gt;

%26lt;/mx:Canvas%26gt;

%26lt;mx:TileList id=''profile1NewsAndSportLinkChoice'' fontWeight=''bold'' dragEnabled=''true'' dragMoveEnabled=''true'' dropEnabled=''true'' height=''292'' width=''650'' left=''21'' columnCount=''5'' rowHeight=''145'' columnWidth=''125'' itemClick=''titleLabel.text=profile1NewsAndSportLinkChoice.selectedItem.title; websiteLinkLabel.text=profile1NewsAndSportLinkChoice.selectedItem.link; descLabel.text=profile1NewsAndSportLinkChoice.selectedItem.description; linkImage.source=profile1NewsAndSportLinkChoice.selectedItem.largeImage;'' itemDoubleClick=''{navigateToURL(new URLRequest('http://' + profile1NewsAndSportLinkChoice.selectedItem.link))}'' doubleClickEnabled=''true'' backgroundColor=''#000000'' borderColor=''#FFFFFF'' color=''#FFFFFF'' borderSides=''top right left'' y=''325''

/%26gt;

%26lt;/mx:WindowedApplication%26gt;

Bizarre TileList problem in AIR that...

Put your itemClick handler code in a function and check for null. May need to do this for both TileListt

private function itemClickFunc():void{
if(profile1NewsAndSportAddLinksTilelist.selectedItem != null){
titleLabel.text=profile1NewsAndSportAddLinksTilelist.selectedItem.title;
?websiteLinkLabel.text=profile1NewsAndSportAddLinksTilelist.selectedItem.link;
?descLabel.text=profile1NewsAndSportAddLinksTilelist.selectedItem.description;
?linkImage.source=profile1NewsAndSportAddLinksTilelist.selectedItem.largeImage;?
}
}

If this post answers your question or helps, please mark it as such.

Bizarre TileList problem in AIR that...

Perfect. Works fine. Now I'll just have to apply that code to the other 20 tilelists that I've got in my Full application

Cheers

No comments:

Post a Comment